Add in a few extra plugins

This commit is contained in:
2025-11-12 00:23:19 +00:00
parent 60c716490f
commit 7e7834cee0
36 changed files with 1852 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.16)
project(CalculatorPlugin VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(GNUInstallDirs)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widgets)
qt_add_plugin(CalculatorPlugin)
target_sources(CalculatorPlugin PRIVATE
CalculatorPlugin.cpp CalculatorPlugin.h
button.cpp button.h
)
target_link_libraries(CalculatorPlugin PRIVATE
Qt::Core
Qt::Gui
Qt::Widgets
)

View File

@@ -0,0 +1,334 @@
#include "CalculatorPlugin.h"
#include "button.h"
#include <QVBoxLayout>
#include <QWidget>
QString CalculatorPlugin::pname()
{
return "Calculator Plugin";
}
QString CalculatorPlugin::pdesc()
{
return "Simple Calculator Plugin.";
}
QWidget* CalculatorPlugin::pcontent()
{
QWidget *test = new QWidget();
display = new QLineEdit("0");
//! [1] //! [2]
display->setReadOnly(true);
display->setAlignment(Qt::AlignRight);
display->setMaxLength(15);
QFont font = display->font();
font.setPointSize(font.pointSize() + 8);
display->setFont(font);
//! [2]
//! [4]
for (int i = 0; i < NumDigitButtons; ++i)
digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked()));
Button *pointButton = createButton(tr("."), SLOT(pointClicked()));
Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked()));
Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked()));
Button *clearButton = createButton(tr("Clear"), SLOT(clear()));
Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll()));
Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory()));
Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory()));
Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory()));
Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory()));
Button *divisionButton = createButton(tr("\303\267"), SLOT(multiplicativeOperatorClicked()));
Button *timesButton = createButton(tr("\303\227"), SLOT(multiplicativeOperatorClicked()));
Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked()));
Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked()));
Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked()));
Button *powerButton = createButton(tr("x\302\262"), SLOT(unaryOperatorClicked()));
Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked()));
Button *equalButton = createButton(tr("="), SLOT(equalClicked()));
//! [4]
//! [5]
QGridLayout *mainLayout = new QGridLayout;
//! [5] //! [6]
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
mainLayout->addWidget(display, 0, 0, 1, 6);
mainLayout->addWidget(backspaceButton, 1, 0, 1, 2);
mainLayout->addWidget(clearButton, 1, 2, 1, 2);
mainLayout->addWidget(clearAllButton, 1, 4, 1, 2);
mainLayout->addWidget(clearMemoryButton, 2, 0);
mainLayout->addWidget(readMemoryButton, 3, 0);
mainLayout->addWidget(setMemoryButton, 4, 0);
mainLayout->addWidget(addToMemoryButton, 5, 0);
for (int i = 1; i < NumDigitButtons; ++i) {
int row = ((9 - i) / 3) + 2;
int column = ((i - 1) % 3) + 1;
mainLayout->addWidget(digitButtons[i], row, column);
}
mainLayout->addWidget(digitButtons[0], 5, 1);
mainLayout->addWidget(pointButton, 5, 2);
mainLayout->addWidget(changeSignButton, 5, 3);
mainLayout->addWidget(divisionButton, 2, 4);
mainLayout->addWidget(timesButton, 3, 4);
mainLayout->addWidget(minusButton, 4, 4);
mainLayout->addWidget(plusButton, 5, 4);
mainLayout->addWidget(squareRootButton, 2, 5);
mainLayout->addWidget(powerButton, 3, 5);
mainLayout->addWidget(reciprocalButton, 4, 5);
mainLayout->addWidget(equalButton, 5, 5);
test->setLayout(mainLayout);
test->setWindowTitle(tr("Calculator Plugin"));
QIcon icon = QIcon(":/images/monkey.png");
test->setWindowIcon(icon);
return test;
}
Button *CalculatorPlugin::createButton(const QString &text, const char *member)
{
Button *button = new Button(text);
connect(button, SIGNAL(clicked()), this, member);
return button;
}
void CalculatorPlugin::digitClicked()
{
Button *clickedButton = qobject_cast<Button *>(sender());
int digitValue = clickedButton->text().toInt();
if (display->text() == "0" && digitValue == 0.0)
return;
if (waitingForOperand) {
display->clear();
waitingForOperand = false;
}
display->setText(display->text() + QString::number(digitValue));
}
void CalculatorPlugin::clear()
{
if (waitingForOperand)
return;
display->setText("0");
waitingForOperand = true;
}
void CalculatorPlugin::clearAll()
{
sumSoFar = 0.0;
factorSoFar = 0.0;
pendingAdditiveOperator.clear();
pendingMultiplicativeOperator.clear();
display->setText("0");
waitingForOperand = true;
}
void CalculatorPlugin::backspaceClicked()
{
if (waitingForOperand)
return;
QString text = display->text();
text.chop(1);
if (text.isEmpty()) {
text = "0";
waitingForOperand = true;
}
display->setText(text);
}
void CalculatorPlugin::pointClicked()
{
if (waitingForOperand)
display->setText("0");
if (!display->text().contains('.'))
display->setText(display->text() + tr("."));
waitingForOperand = false;
}
void CalculatorPlugin::changeSignClicked()
{
QString text = display->text();
double value = text.toDouble();
if (value > 0.0) {
text.prepend(tr("-"));
} else if (value < 0.0) {
text.remove(0, 1);
}
display->setText(text);
}
void CalculatorPlugin::equalClicked()
{
double operand = display->text().toDouble();
if (!pendingMultiplicativeOperator.isEmpty()) {
if (!calculate(operand, pendingMultiplicativeOperator)) {
abortOperation();
return;
}
operand = factorSoFar;
factorSoFar = 0.0;
pendingMultiplicativeOperator.clear();
}
if (!pendingAdditiveOperator.isEmpty()) {
if (!calculate(operand, pendingAdditiveOperator)) {
abortOperation();
return;
}
pendingAdditiveOperator.clear();
} else {
sumSoFar = operand;
}
display->setText(QString::number(sumSoFar));
sumSoFar = 0.0;
waitingForOperand = true;
}
bool CalculatorPlugin::calculate(double rightOperand, const QString &pendingOperator)
{
if (pendingOperator == tr("+")) {
sumSoFar += rightOperand;
} else if (pendingOperator == tr("-")) {
sumSoFar -= rightOperand;
} else if (pendingOperator == tr("\303\227")) {
factorSoFar *= rightOperand;
} else if (pendingOperator == tr("\303\267")) {
if (rightOperand == 0.0)
return false;
factorSoFar /= rightOperand;
}
return true;
}
void CalculatorPlugin::additiveOperatorClicked()
//! [10] //! [11]
{
Button *clickedButton = qobject_cast<Button *>(sender());
if (!clickedButton)
return;
QString clickedOperator = clickedButton->text();
double operand = display->text().toDouble();
//! [11] //! [12]
if (!pendingMultiplicativeOperator.isEmpty()) {
//! [12] //! [13]
if (!calculate(operand, pendingMultiplicativeOperator)) {
abortOperation();
return;
}
display->setText(QString::number(factorSoFar));
operand = factorSoFar;
factorSoFar = 0.0;
pendingMultiplicativeOperator.clear();
}
//! [13] //! [14]
if (!pendingAdditiveOperator.isEmpty()) {
//! [14] //! [15]
if (!calculate(operand, pendingAdditiveOperator)) {
abortOperation();
return;
}
display->setText(QString::number(sumSoFar));
} else {
sumSoFar = operand;
}
//! [15] //! [16]
pendingAdditiveOperator = clickedOperator;
//! [16] //! [17]
waitingForOperand = true;
}
void CalculatorPlugin::unaryOperatorClicked()
//! [8] //! [9]
{
Button *clickedButton = qobject_cast<Button *>(sender());
QString clickedOperator = clickedButton->text();
double operand = display->text().toDouble();
double result = 0.0;
if (clickedOperator == tr("Sqrt")) {
if (operand < 0.0) {
abortOperation();
return;
}
result = std::sqrt(operand);
} else if (clickedOperator == tr("x\302\262")) {
result = std::pow(operand, 2.0);
} else if (clickedOperator == tr("1/x")) {
if (operand == 0.0) {
abortOperation();
return;
}
result = 1.0 / operand;
}
display->setText(QString::number(result));
waitingForOperand = true;
}
void CalculatorPlugin::abortOperation()
{
clearAll();
display->setText(tr("####"));
}
void CalculatorPlugin::clearMemory()
{
sumInMemory = 0.0;
}
void CalculatorPlugin::readMemory()
{
display->setText(QString::number(sumInMemory));
waitingForOperand = true;
}
void CalculatorPlugin::setMemory()
{
equalClicked();
sumInMemory = display->text().toDouble();
}
void CalculatorPlugin::addToMemory()
{
equalClicked();
sumInMemory += display->text().toDouble();
}
void CalculatorPlugin::multiplicativeOperatorClicked()
{
Button *clickedButton = qobject_cast<Button *>(sender());
if (!clickedButton)
return;
QString clickedOperator = clickedButton->text();
double operand = display->text().toDouble();
if (!pendingMultiplicativeOperator.isEmpty()) {
if (!calculate(operand, pendingMultiplicativeOperator)) {
abortOperation();
return;
}
display->setText(QString::number(factorSoFar));
} else {
factorSoFar = operand;
}
pendingMultiplicativeOperator = clickedOperator;
waitingForOperand = true;
}

View File

@@ -0,0 +1,59 @@
#ifndef CALCULATORPLUGIN_H
#define CALCULATORPLUGIN_H
#include <../../src/interface.h>
#include <cmath>
#include <QObject>
#include <QtPlugin>
#include <QString>
#include <QWidget>
#include <QImage>
#include <QLineEdit>
QT_BEGIN_NAMESPACE
class QLineEdit;
QT_END_NAMESPACE
class Button;
class CalculatorPlugin : public QObject, public Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.SOM.Interface" FILE "CalculatorPlugin.json")
Q_INTERFACES(Interface)
public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
private:
QLineEdit *display;
enum { NumDigitButtons = 10 };
Button *digitButtons[NumDigitButtons];
Button *createButton(const QString &text, const char *member);
bool waitingForOperand;
double sumSoFar;
double factorSoFar;
double sumInMemory;
QString pendingAdditiveOperator;
QString pendingMultiplicativeOperator;
void abortOperation();
bool calculate(double rightOperand, const QString &pendingOperator);
private slots:
void digitClicked();
void unaryOperatorClicked();
void additiveOperatorClicked();
void multiplicativeOperatorClicked();
void equalClicked();
void pointClicked();
void changeSignClicked();
void backspaceClicked();
void clear();
void clearAll();
void clearMemory();
void readMemory();
void setMemory();
void addToMemory();
};
#endif

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "button.h"
//! [0]
Button::Button(const QString &text, QWidget *parent)
: QToolButton(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setText(text);
}
//! [0]
//! [1]
QSize Button::sizeHint() const
//! [1] //! [2]
{
QSize size = QToolButton::sizeHint();
size.rheight() += 20;
size.rwidth() = qMax(size.width(), size.height());
return size;
}
//! [2]

View File

@@ -0,0 +1,68 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef BUTTON_H
#define BUTTON_H
#include <QToolButton>
//! [0]
class Button : public QToolButton
{
Q_OBJECT
public:
explicit Button(const QString &text, QWidget *parent = nullptr);
QSize sizeHint() const override;
};
//! [0]
#endif

View File

@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.16)
project(IrcClientPlugin VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(GNUInstallDirs)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Network Widgets)
qt_add_plugin(IrcClientPlugin)
target_sources(IrcClientPlugin PRIVATE
IrcClientPlugin.cpp IrcClientPlugin.h
client.cpp client.h
hostmask.cpp hostmask.h
joinmessagehandler.cpp joinmessagehandler.h
message.cpp message.h
messagehandler.cpp messagehandler.h
pingmessagehandler.cpp pingmessagehandler.h
privmsgmessagehandler.cpp privmsgmessagehandler.h
quitmessagehandler.cpp quitmessagehandler.h
testhandler.cpp testhandler.h
topichandler.cpp topichandler.h
)
target_link_libraries(IrcClientPlugin PRIVATE
Qt::Core
Qt::Gui
Qt::Network
Qt::Widgets
)
# Resources:
set(IrcClientPlugin_resource_files
"images/smile.png"
)
qt_add_resources(IrcClientPlugin "IrcClientPlugin"
PREFIX
"/"
FILES
${IrcClientPlugin_resource_files}
)

View File

@@ -0,0 +1,269 @@
#include "IrcClientPlugin.h"
#include "pingmessagehandler.h"
#include "privmsgmessagehandler.h"
#include "testhandler.h"
#include "topichandler.h"
#include "joinmessagehandler.h"
#include "quitmessagehandler.h"
#include <QVBoxLayout>
#include <QtWidgets>
QString IrcClientPlugin::pname()
{
return "Irc Client Plugin";
}
QString IrcClientPlugin::pdesc()
{
return "Simple Irc Client Plugin";
}
QWidget* IrcClientPlugin::pcontent()
{
connectButton = new QPushButton(tr("Connect"));
connect(connectButton, SIGNAL(clicked()), this, SLOT(connectToServer()));
sendButton = new QPushButton(tr("Send"));
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMsg()));
joinButton = new QPushButton(tr("Join"));
connect(joinButton, SIGNAL(clicked()), this, SLOT(joinRoom()));
smallEditor = new QLineEdit;
smallEditor->setText("");
topic = new QLineEdit;
topic->setText("");
msgs = new QTextBrowser;
nicks = new QTextEdit;
nicks->setMinimumWidth(100);
nicks->setMaximumWidth(100);
msgs->setOpenExternalLinks(true);
connect(msgs, SIGNAL(textChanged()), this, SLOT(changePixmap())) ;
test = new QWidget();
test->setWindowTitle(tr("Irc Client Plugin"));
test->resize(400, 300);
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(connectButton);
topLayout->addWidget(joinButton);
QHBoxLayout *midleLayout = new QHBoxLayout;
midleLayout->addWidget(msgs);
midleLayout->addWidget(nicks);
QHBoxLayout *bottomLayout = new QHBoxLayout;
// topLayout->addWidget(ftpServerLabel);
bottomLayout->addWidget(smallEditor);
//topLayout->addWidget(cdToParentButton);
bottomLayout->addWidget(sendButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addWidget(topic);
mainLayout->addLayout(midleLayout);
// mainLayout->addWidget(msgs);
//mainLayout->addWidget(statusLabel);
mainLayout->addLayout(bottomLayout);
test->setLayout(mainLayout);
QIcon icon = QIcon(":/images/monkey.png");
test->setWindowIcon(icon);
return test;
}
void IrcClientPlugin::changePixmap()
{
QRegularExpression reg1(":\\)");
QTextCursor cursor1(msgs->document()->find(reg1));
if (!cursor1.isNull()) {
cursor1.insertHtml("<img src=\":/images/smile.png\">");
}
//auto text = msgs->toHtml();
// if(text != ""){
// QRegExp exp("<\sa\s+[^>]href\s=\s\"([^\"])\"\s>(.)<\/\sa\s*>");
// text.replace(exp, "{{\1}}");
// msgs->setHtml(text);
//}
//QRegExp reg(":\\("); // you can improve regular expression
QRegularExpression reg("https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)");
QTextCursor cursor(msgs->document()->find(reg));
if (!cursor.isNull()) {
QString nlink = "<a href=\"http://barosonix.com\">http://barosonix.com</a>";
cursor.insertHtml(nlink);
}
}
void IrcClientPlugin::connectToServer()
{
_client = new Client(test);
connect(_client, SIGNAL(PrivmsgReceived(Hostmask,QString,QString)), SLOT(onPrivmsgReceived(Hostmask,QString,QString)));
connect(_client, SIGNAL(NamesListReceived(QString)), SLOT(onNamesListReceived(QString)));
connect(_client, SIGNAL(JoinMsgReceived(Hostmask,QString,QString)), SLOT(onJoinMsgReceived(Hostmask,QString,QString)));
connect(_client, SIGNAL(QuitMsgReceived(Hostmask,QString,QString)), SLOT(onQuitMsgReceived(Hostmask,QString,QString)));
connect(_client, SIGNAL(TopicReceived(Hostmask,QString,QString)), SLOT(onTopicReceived(Hostmask,QString,QString)));
_client->setNickname("ahf_");
_client->setUsername("ahf");
_client->setRealname(QString::fromUtf8("Alexander Færøy"));
_client->setServerHostname("127.0.0.1");
_client->setServerPort(6667);
_client->registerMessageHandler("PING", new PingMessageHandler);
_client->registerMessageHandler("PRIVMSG", new PrivmsgMessageHandler);
_client->registerMessageHandler("353", new testhandler);
_client->registerMessageHandler("332", new topichandler);
_client->registerMessageHandler("JOIN", new joinmessagehandler);
_client->registerMessageHandler("PART", new quitmessagehandler);
_client->connectToServer();
}
void IrcClientPlugin::sendMsg()
{
QString input;
input = smallEditor->text();
if (input.isEmpty())
return;
if (input.at(0) == '/')
{
QString command = input.mid(1);
_client->sendRaw(command);
}
else
{
_client->sendPrivmsg("#test", input);
QString format;
format = "<font style='color: blue'>" + _client->getNickname() + "</font> " + input;
append(format);
}
smallEditor->clear();
}
void IrcClientPlugin::joinRoom()
{
_client->sendJoin("#test");
}
void IrcClientPlugin::onPrivmsgReceived(const Hostmask &hostmask, const QString &target, const QString &text)
{
QString format;
format = "<" + hostmask.getNickname() + "> " + text;
append(format);
}
void IrcClientPlugin::onNamesListReceived(const QString &text)
{
//QString format;
int marker = 0;
// qDebug() << "GOT:" << text;
QStringList list1 = text.split(QLatin1Char(' '));
for (QString data : list1) // iterate over array fibonacci
{
marker = marker +1;
if(marker > 2)
{
nicks->append(data);
// qDebug() << "GOT:" << data;
}
}
//format = "<" + hostmask.getNickname() + "> " + text;
//append(format);
}
void IrcClientPlugin::onJoinMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text)
{
if(hostmask.getNickname() != _client->getNickname())
{
QString format;
qDebug() << "GOT:" << text;
format = "<" + hostmask.getNickname() + "> Has Joined.";
nicks->append(hostmask.getNickname());
append(format);
}
}
void IrcClientPlugin::onTopicReceived(const Hostmask& hostmask, const QString& target, const QString& text)
{
int marker = 0;
QString ftext = "";
QStringList list1 = text.split(QLatin1Char(' '));
for (QString data : list1) // iterate over array fibonacci
{
marker = marker +1;
if(marker > 1)
{
if(ftext != "")
{
ftext += " " + data;
}
else
{
ftext += data;
}
// qDebug() << "GOT:" << data;
}
}
// if(hostmask.getNickname() != _client->getNickname())
//{
// QString format;
qDebug() << "GOT:" << ftext;
topic->setText(ftext);
// format = "<" + hostmask.getNickname() + "> Has Joined.";
// nicks->append(hostmask.getNickname());
// append(format);
// }
}
void IrcClientPlugin::onQuitMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text)
{
QString format;
qDebug() << "GOT:" << text;
format = "<" + hostmask.getNickname() + "> Has Quit.";
QStringList lines = nicks->toPlainText().split("\n");
int i = 0;
while(i < lines.size())
{
QString line = lines.at(i);
if(line.contains(hostmask.getNickname()))
{
lines.removeAt(i);
}
else
{
i++;
}
}
nicks->setPlainText(lines.join("\n"));
append(format);
}
void IrcClientPlugin::append(const QString &line)
{
msgs->append(line);
}

View File

@@ -0,0 +1,59 @@
#ifndef TESTPLUGIN_H
#define TESTPLUGIN_H
#include <../../src/interface.h>
#include "client.h"
#include "hostmask.h"
#include <QtWidgets>
QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QFile;
class QFtp;
class QLabel;
class QLineEdit;
class QTreeWidget;
class QTreeWidgetItem;
class QPushButton;
class QUrlInfo;
class QNetworkSession;
QT_END_NAMESPACE
class IrcClientPlugin : public QObject, public Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.SOM.Interface" FILE "IrcClientPlugin.json")
Q_INTERFACES(Interface)
public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
private:
void append(const QString& line);
QWidget *test;
QPushButton *sendButton;
QPushButton *connectButton;
QPushButton *joinButton;
QLineEdit *smallEditor;
QLineEdit *topic;
QTextBrowser *msgs;
QTextEdit *nicks;
Client *_client;
private slots:
void connectToServer();
void changePixmap();
void joinRoom();
void sendMsg();
void onPrivmsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
void onNamesListReceived(const QString& text);
void onJoinMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
void onQuitMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
void onTopicReceived(const Hostmask& hostmask, const QString& target, const QString& text);
};
#endif

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>images/smile.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,183 @@
#include "client.h"
//#include <QtDebug>
Client::Client(QObject *parent) :
QObject(parent)
{
_socket = new QSslSocket(this);
// We ignore SSL errors since most IRC servers uses invalid certificates.
connect(_socket, SIGNAL(sslErrors(QList<QSslError>)), _socket, SLOT(ignoreSslErrors()));
connect(_socket, SIGNAL(connected()), SLOT(connectionEstablished()));
connect(_socket, SIGNAL(readyRead()), SLOT(readData()));
// Send messages to dispatching.
connect(this, SIGNAL(ReceivedMessage(Message)), SLOT(dispatchMessage(Message)));
}
Client::~Client()
{
}
void Client::sendNick(const QString &nickname)
{
writeLine(QString("NICK %1").arg(nickname));
// We set it here to keep track of it.
_nickname = nickname;
}
void Client::sendUser(const QString &username, const QString &realname, const QString &hostname)
{
writeLine(QString("USER %1 %1 %2 :%3").arg(username).arg(hostname).arg(realname));
}
void Client::sendJoin(const QString &channel)
{
writeLine(QString("JOIN %1").arg(channel));
}
void Client::sendQuit(const QString &message)
{
writeLine(QString("QUIT :%1").arg(message));
}
void Client::sendPong(const QString &message)
{
writeLine(QString("PONG :%1").arg(message));
}
void Client::sendRaw(const QString &message)
{
writeLine(message);
}
void Client::sendPrivmsg(const QString &target, const QString &text)
{
writeLine(QString("PRIVMSG %1 :%2").arg(target).arg(text));
}
void Client::didReceivePrivmsg(const Hostmask &hostmask, const QString &target, const QString &text)
{
emit PrivmsgReceived(hostmask, target, text);
}
void Client::didReceiveNamesList(const QString &text)
{
emit NamesListReceived(text);
}
void Client::didReceiveQuitMsg(const Hostmask& hostmask, const QString& target, const QString& text)
{
emit QuitMsgReceived(hostmask, target, text);
}
void Client::didReceiveTopic(const Hostmask& hostmask, const QString& target, const QString& text)
{
emit TopicReceived(hostmask, target, text);
}
void Client::didReceiveJoinMsg(const Hostmask &hostmask, const QString &target, const QString &text)
{
emit JoinMsgReceived(hostmask, target, text);
}
void Client::connectToServer()
{
_socket->connectToHost(_server_hostname, _server_port);
}
void Client::writeLine(const QString &line)
{
qDebug() << "Send:" << line;
_socket->write(QString("%1\r\n").arg(line).toUtf8());
}
void Client::connectionEstablished()
{
qDebug() << "Connection Established";
sendNick(_nickname);
sendUser(_username, _realname, _socket->peerName());
emit Connected();
}
void Client::readData()
{
while (_socket->canReadLine())
{
QString line = QString::fromUtf8(_socket->readLine());
line.remove("\r\n");
qDebug() << "Recv:" << line;
emit ReceivedMessage(Message::parse(line));
}
}
void Client::registerMessageHandler(const QString& command, MessageHandler* handler)
{
_message_handlers[command.toLower()].append(handler);
handler->setParent(this);
}
void Client::dispatchMessage(const Message& message)
{
foreach (MessageHandler* handler, _message_handlers[message.getCommand().toLower()])
{
handler->handle(this, message);
}
}
void Client::setServerHostname(const QString &hostname)
{
_server_hostname = hostname;
}
void Client::setServerPort(quint16 port)
{
_server_port = port;
}
QString Client::getServerHostname() const
{
return _server_hostname;
}
quint16 Client::getServerPort() const
{
return _server_port;
}
QString Client::getNickname() const
{
return _nickname;
}
QString Client::getUsername() const
{
return _nickname;
}
QString Client::getRealname() const
{
return _realname;
}
void Client::setNickname(const QString &nickname)
{
_nickname = nickname;
}
void Client::setUsername(const QString &username)
{
_username = username;
}
void Client::setRealname(const QString &realname)
{
_realname = realname;
}

View File

@@ -0,0 +1,83 @@
#ifndef CLIENT_H
#define CLIENT_H
#include <QObject>
#include <QSslSocket>
#include <QHash>
#include "messagehandler.h"
#include "message.h"
#include "hostmask.h"
class Client : public QObject
{
Q_OBJECT
public:
Client(QObject *parent = 0);
~Client();
void connectToServer();
void setNickname(const QString& nickname);
void setRealname(const QString& realname);
void setUsername(const QString& username);
QString getNickname() const;
QString getUsername() const;
QString getRealname() const;
void setServerHostname(const QString& hostname);
void setServerPort(quint16 port);
QString getServerHostname() const;
quint16 getServerPort() const;
void registerMessageHandler(const QString& command, MessageHandler* handler);
void sendNick(const QString& nickname);
void sendUser(const QString& username, const QString& realname, const QString& hostname);
void sendJoin(const QString& channel);
void sendQuit(const QString& message);
void sendPong(const QString& message);
void sendRaw(const QString& message);
void sendPrivmsg(const QString& target, const QString& text);
void didReceivePrivmsg(const Hostmask& hostmask, const QString& target, const QString& text);
void didReceiveNamesList(const QString& text);
void didReceiveJoinMsg(const Hostmask& hostmask, const QString& target, const QString& text);
void didReceiveQuitMsg(const Hostmask &hostmask, const QString &target, const QString& text);
void didReceiveTopic(const Hostmask &hostmask, const QString &target, const QString& text);
signals:
void ReceivedMessage(const Message& message);
void Connected();
void PrivmsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
void NamesListReceived(const QString& text);
void JoinMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
void QuitMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
void TopicReceived(const Hostmask& hostmask, const QString& target, const QString& text);
private slots:
void readData();
void connectionEstablished();
void dispatchMessage(const Message& message);
private:
void writeLine(const QString& line);
QString _nickname;
QString _username;
QString _realname;
QString _server_hostname;
int _server_port;
QSslSocket *_socket;
QHash<QString, QList<MessageHandler*> > _message_handlers;
};
#endif // CLIENT_H

View File

@@ -0,0 +1,44 @@
#include "hostmask.h"
Hostmask::Hostmask(const QString& nickname, const QString& username, const QString& hostname) :
_nickname(nickname),
_username(username),
_hostname(hostname)
{
}
QString Hostmask::toString() const
{
return _nickname + "!" + _username + "@" + _hostname;
}
QString Hostmask::getNickname() const
{
return _nickname;
}
QString Hostmask::getUsername() const
{
return _username;
}
QString Hostmask::getHostname() const
{
return _hostname;
}
Hostmask Hostmask::parse(const QString &l)
{
QString nickname;
QString username;
QString hostname;
int at_pos = l.indexOf('@');
int exclamation_mark_pos = l.indexOf('!');
nickname = l.left(exclamation_mark_pos);
username = l.mid(exclamation_mark_pos + 1, at_pos - exclamation_mark_pos - 1);
hostname = l.mid(at_pos + 1, l.size());
return Hostmask(nickname, username, hostname);
}

View File

@@ -0,0 +1,27 @@
#ifndef HOSTMASK_H
#define HOSTMASK_H
// nick!~ahf@hostname
#include <QString>
class Hostmask
{
public:
QString getNickname() const;
QString getUsername() const;
QString getHostname() const;
QString toString() const;
static Hostmask parse(const QString& l);
protected:
Hostmask(const QString& nickname, const QString& username, const QString& hostname);
private:
QString _nickname;
QString _username;
QString _hostname;
};
#endif // HOSTMASK_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 819 B

View File

@@ -0,0 +1,24 @@
#include "joinmessagehandler.h"
joinmessagehandler::joinmessagehandler()
{
}
void joinmessagehandler::handle(Client *client, const Message &message)
{
QString target = message.getTarget();
QString text = message.getArguments().join(" ");
Hostmask from = Hostmask::parse(message.getPrefix());
client->didReceiveJoinMsg(from, target, text);
// for (QString data : message.getArguments()) // iterate over array fibonacci
// {
// qDebug() << "GOT:" << data;
// }
//QString pongMessage = message.getTarget();
//client->sendPong(pongMessage);
}

View File

@@ -0,0 +1,15 @@
#ifndef JOINMESSAGEHANDLER_H
#define JOINMESSAGEHANDLER_H
#include "message.h"
#include "client.h"
#include "messagehandler.h"
class joinmessagehandler: public MessageHandler
{
public:
joinmessagehandler();
virtual void handle(Client *client, const Message& message);
};
#endif // JOINMESSAGEHANDLER_H

View File

@@ -0,0 +1,81 @@
#include "message.h"
#include <QtDebug>
Message::Message(const QString& prefix, const QString& target, const QString& command, const QString& raw, const QStringList& arguments) :
_prefix(prefix),
_target(target),
_command(command),
_raw_line(raw),
_arguments(arguments)
{
}
Message Message::parse(const QString &l)
{
QString prefix;
QString target;
QString command;
QStringList arguments;
QString raw(l);
QString line(l);
int pos = 0;
if (line.startsWith(':'))
{
pos = line.indexOf(' ', 1);
prefix = line.mid(1, pos - 1);
line = line.mid(pos + 1, line.length());
}
if (-1 != (pos = line.indexOf(" :")))
{
QString tmp(line.mid(pos + 2, line.length()));
arguments.append(line.left(pos).split(' '));
arguments.append(tmp.split(' '));
}
else
{
arguments = line.split(' ');
}
if (! arguments.isEmpty())
{
command = arguments.front();
arguments.pop_front();
}
if (! arguments.isEmpty())
{
target = arguments.front();
arguments.pop_front();
}
return Message(prefix, target, command, raw, arguments);
}
QString Message::getPrefix() const
{
return _prefix;
}
QString Message::getTarget() const
{
return _target;
}
QString Message::getCommand() const
{
return _command;
}
QString Message::getRawLine() const
{
return _raw_line;
}
QStringList Message::getArguments() const
{
return _arguments;
}

View File

@@ -0,0 +1,30 @@
#ifndef MESSAGE_H
#define MESSAGE_H
#include <QString>
#include <QStringList>
class Message
{
public:
static Message parse(const QString& l);
QString getPrefix() const;
QString getTarget() const;
QString getCommand() const;
QString getRawLine() const;
QStringList getArguments() const;
protected:
Message(const QString& prefix, const QString& target, const QString& command, const QString& raw, const QStringList& arguments);
private:
QString _prefix;
QString _target;
QString _command;
QString _raw_line;
QStringList _arguments;
};
#endif // MESSAGE_H

View File

@@ -0,0 +1,6 @@
#include "messagehandler.h"
MessageHandler::MessageHandler() :
QObject(0)
{
}

View File

@@ -0,0 +1,20 @@
#ifndef MESSAGEHANDLER_H
#define MESSAGEHANDLER_H
#include <QObject>
class Client;
class Message;
class MessageHandler : public QObject
{
Q_OBJECT
protected:
MessageHandler();
public:
virtual void handle(Client* client, const Message &message) = 0;
};
#endif // MESSAGEHANDLER_H

View File

@@ -0,0 +1,11 @@
#include "pingmessagehandler.h"
PingMessageHandler::PingMessageHandler()
{
}
void PingMessageHandler::handle(Client *client, const Message &message)
{
QString pongMessage = message.getTarget();
client->sendPong(pongMessage);
}

View File

@@ -0,0 +1,15 @@
#ifndef PINGMESSAGEHANDLER_H
#define PINGMESSAGEHANDLER_H
#include "message.h"
#include "client.h"
#include "messagehandler.h"
class PingMessageHandler : public MessageHandler
{
public:
PingMessageHandler();
virtual void handle(Client *client, const Message& message);
};
#endif // PINGMESSAGEHANDLER_H

View File

@@ -0,0 +1,19 @@
#include "privmsgmessagehandler.h"
#include "hostmask.h"
PrivmsgMessageHandler::PrivmsgMessageHandler()
{
// _tray_icon = new QSystemTrayIcon(this);
// _tray_icon->show();
}
void PrivmsgMessageHandler::handle(Client *client, const Message &message)
{
QString target = message.getTarget();
QString text = message.getArguments().join(" ");
Hostmask from = Hostmask::parse(message.getPrefix());
client->didReceivePrivmsg(from, target, text);
// _tray_icon->showMessage("Message Received", text);
}

View File

@@ -0,0 +1,21 @@
#ifndef PRIVMSGMESSAGEHANDLER_H
#define PRIVMSGMESSAGEHANDLER_H
#include "messagehandler.h"
#include "client.h"
#include "message.h"
//#include <QSystemTrayIcon>
class PrivmsgMessageHandler : public MessageHandler
{
public:
PrivmsgMessageHandler();
virtual void handle(Client *client, const Message &message);
private:
//QSystemTrayIcon *_tray_icon;
};
#endif // PRIVMSGMESSAGEHANDLER_H

View File

@@ -0,0 +1,23 @@
#include "quitmessagehandler.h"
quitmessagehandler::quitmessagehandler()
{
}
void quitmessagehandler::handle(Client *client, const Message &message)
{
QString target = message.getTarget();
QString text = message.getArguments().join(" ");
Hostmask from = Hostmask::parse(message.getPrefix());
client->didReceiveQuitMsg(from, target, text);
// for (QString data : message.getArguments()) // iterate over array fibonacci
// {
// qDebug() << "GOT:" << data;
// }
//QString pongMessage = message.getTarget();
//client->sendPong(pongMessage);
}

View File

@@ -0,0 +1,15 @@
#ifndef QUITMESSAGEHANDLER_H
#define QUITMESSAGEHANDLER_H
#include "message.h"
#include "client.h"
#include "messagehandler.h"
class quitmessagehandler: public MessageHandler
{
public:
quitmessagehandler();
virtual void handle(Client *client, const Message& message);
};
#endif // QUITMESSAGEHANDLER_H

View File

@@ -0,0 +1,21 @@
#include "testhandler.h"
#include <QDebug>
testhandler::testhandler()
{
}
void testhandler::handle(Client *client, const Message &message)
{
QString text = message.getArguments().join(" ");
client->didReceiveNamesList(text);
// for (QString data : message.getArguments()) // iterate over array fibonacci
// {
// qDebug() << "GOT:" << data;
// }
//QString pongMessage = message.getTarget();
//client->sendPong(pongMessage);
}

View File

@@ -0,0 +1,15 @@
#ifndef TESTHANDLER_H
#define TESTHANDLER_H
#include "message.h"
#include "client.h"
#include "messagehandler.h"
class testhandler: public MessageHandler
{
public:
testhandler();
virtual void handle(Client *client, const Message& message);
};
#endif // TESTHANDLER_H

View File

@@ -0,0 +1,24 @@
#include "topichandler.h"
topichandler::topichandler()
{
}
void topichandler::handle(Client *client, const Message &message)
{
QString target = message.getTarget();
QString text = message.getArguments().join(" ");
Hostmask from = Hostmask::parse(message.getPrefix());
client->didReceiveTopic(from, target, text);
// for (QString data : message.getArguments()) // iterate over array fibonacci
// {
// qDebug() << "GOT:" << data;
// }
//QString pongMessage = message.getTarget();
//client->sendPong(pongMessage);
}

View File

@@ -0,0 +1,15 @@
#ifndef TOPICHANDLER_H
#define TOPICHANDLER_H
#include "message.h"
#include "client.h"
#include "messagehandler.h"
class topichandler: public MessageHandler
{
public:
topichandler();
virtual void handle(Client *client, const Message& message);
};
#endif // TOPICHANDLER_H

View File

@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.16)
project(ScreenShotPlugin VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(GNUInstallDirs)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widgets)
qt_add_plugin(ScreenShotPlugin)
target_sources(ScreenShotPlugin PRIVATE
ScreenShotPlugin.cpp ScreenShotPlugin.h
)
target_link_libraries(ScreenShotPlugin PRIVATE
Qt::Core
Qt::Gui
Qt::Widgets
)

View File

@@ -0,0 +1,157 @@
#include "ScreenShotPlugin.h"
//#include <QVBoxLayout>
//#include <QGroupBox>
//#include <QPushButton>
//#include <QScreen>
#include <QtWidgets>
//#include <QSpinBox>
//#include <QCheckBox>
//#include <QPushButton>
//#include <QApplication>
//#include <QTimer>
QString ScreenShotPlugin::pname()
{
return "Screen Shot Plugin";
}
QString ScreenShotPlugin::pdesc()
{
return "Simple Screen Shot Plugin.";
}
QWidget* ScreenShotPlugin::pcontent()
{
test = new QWidget();
test->setWindowTitle(tr("Screen Shot Plugin"));
test->resize(400, 300);
QVBoxLayout *mainLayout = new QVBoxLayout(nullptr);
screenshotLabel = new QLabel;
screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
screenshotLabel->setAlignment(Qt::AlignCenter);
const QRect screenGeometry = test->screen()->geometry();
screenshotLabel->setMinimumSize(screenGeometry.width() / 8, screenGeometry.height() / 8);
mainLayout->addWidget(screenshotLabel);
QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"));
delaySpinBox = new QSpinBox(optionsGroupBox);
delaySpinBox->setSuffix(tr(" s"));
delaySpinBox->setMaximum(60);
connect(delaySpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &ScreenShotPlugin::updateceheck);
hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"), optionsGroupBox);
QGridLayout *optionsGroupBoxLayout = new QGridLayout(optionsGroupBox);
optionsGroupBoxLayout->addWidget(new QLabel(tr("Screenshot Delay:"), nullptr), 0, 0);
optionsGroupBoxLayout->addWidget(delaySpinBox, 0, 1);
optionsGroupBoxLayout->addWidget(hideThisWindowCheckBox, 1, 0, 1, 2);
mainLayout->addWidget(optionsGroupBox);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
newScreenshotButton = new QPushButton(tr("New Screenshot"), test);
connect(newScreenshotButton, &QPushButton::clicked, this, &ScreenShotPlugin::newScreenshot);
buttonsLayout->addWidget(newScreenshotButton);
QPushButton *saveScreenshotButton = new QPushButton(tr("Save Screenshot"));
connect(saveScreenshotButton, &QPushButton::clicked, this, &ScreenShotPlugin::saveScreenshot);
buttonsLayout->addWidget(saveScreenshotButton);
QPushButton *quitScreenshotButton = new QPushButton(tr("Quit"));
quitScreenshotButton->setShortcut(Qt::CTRL + Qt::Key_Q);
connect(quitScreenshotButton, &QPushButton::clicked, test, &QWidget::close);
buttonsLayout->addWidget(quitScreenshotButton);
buttonsLayout->addStretch();
mainLayout->addLayout(buttonsLayout);
delaySpinBox->setValue(5);
test->setLayout(mainLayout);
QTimer::singleShot(250, this, &ScreenShotPlugin::shootScreen);
QIcon icon = QIcon(":/images/monkey.png");
test->setWindowIcon(icon);
return test;
}
void ScreenShotPlugin::updateScreenshotLabel()
{
screenshotLabel->setPixmap(originalPixmap.scaled(screenshotLabel->size(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation));
}
void ScreenShotPlugin::shootScreen()
{
QScreen *screen = QGuiApplication::primaryScreen();
if (QWindow *window = test->windowHandle())
screen = window->screen();
if (!screen)
return;
if (delaySpinBox->value() != 0)
QApplication::beep();
originalPixmap = screen->grabWindow(0);
updateScreenshotLabel();
newScreenshotButton->setDisabled(false);
if (hideThisWindowCheckBox->isChecked())
test->show();
}
void ScreenShotPlugin::saveScreenshot()
{
QString d = QDate::currentDate().toString();
QString t = QTime::currentTime().toString();
const QString format = "png";
QString initialPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
if (initialPath.isEmpty())
initialPath = QDir::currentPath();
initialPath += tr("/ScreenShot_") + t + "-" + d + "." + format;
QFileDialog fileDialog(test, tr("Save As"), initialPath);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setDirectory(initialPath);
QStringList mimeTypes;
const QList<QByteArray> baMimeTypes = QImageWriter::supportedMimeTypes();
for (const QByteArray &bf : baMimeTypes)
mimeTypes.append(QLatin1String(bf));
fileDialog.setMimeTypeFilters(mimeTypes);
fileDialog.selectMimeTypeFilter("image/" + format);
fileDialog.setDefaultSuffix(format);
if (fileDialog.exec() != QDialog::Accepted)
return;
const QString fileName = fileDialog.selectedFiles().first();
if (!originalPixmap.save(fileName)) {
QMessageBox::warning(test, tr("Save Error"), tr("The image could not be saved to \"%1\".")
.arg(QDir::toNativeSeparators(fileName)));
}
}
void ScreenShotPlugin::newScreenshot()
{
if (hideThisWindowCheckBox->isChecked())
test->hide();
newScreenshotButton->setDisabled(true);
//shootScreen();
QTimer::singleShot(delaySpinBox->value() * 1000, this, &ScreenShotPlugin::shootScreen);
}
void ScreenShotPlugin::updateceheck()
{
if (delaySpinBox->value() == 0) {
hideThisWindowCheckBox->setDisabled(true);
hideThisWindowCheckBox->setChecked(false);
} else {
hideThisWindowCheckBox->setDisabled(false);
}
}

View File

@@ -0,0 +1,50 @@
#ifndef TESTPLUGIN_H
#define TESTPLUGIN_H
#include <../../src/interface.h>
#include <QObject>
#include <QtPlugin>
#include <QString>
#include <QWidget>
#include <QImage>
#include <QLabel>
#include <QCheckBox>
#include <QSpinBox>
#include <QPushButton>
#include <QPixmap>
class ScreenShotPlugin : public QObject, public Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.SOM.Interface" FILE "ScreenShotPlugin.json")
Q_INTERFACES(Interface)
public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override ;
public slots:
void updateceheck();
private slots:
void shootScreen();
void newScreenshot();
void saveScreenshot();
private:
void updateScreenshotLabel();
QLabel *screenshotLabel;
QCheckBox *hideThisWindowCheckBox;
QSpinBox *delaySpinBox;
QPushButton *newScreenshotButton;
QPixmap originalPixmap;
QWidget *test;
};
#endif

View File

@@ -0,0 +1 @@
{}