//main.cpp
#include <QtGui>
#include "window.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(systray);
Window box;
MainWindow window;
window.setParent(&box);
return app.exec();
}
//mainwindow.cpp
#include <QtGui>
class QWebView;
//! [1]
{
Q_OBJECT
public:
MainWindow();
private:
QWebView *view;
};
//window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QDialog>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QLineEdit>
#include <QTextEdit>
{
Q_OBJECT
public:
Window();
private slots:
void setIcon();
void showMessage();
private:
void createActions();
void createTrayIcon();
};
#endif
//window.cpp
#include <QtGui>
#include <QtWebKit>
#include <QTime>
#include "window.h"
#include "mainwindow.h"
Window::Window()
{
createActions();
createTrayIcon();
setIcon();
trayIcon->show();
setWindowTitle(tr("Blog Search"));
resize(600, 600);
}
MainWindow::MainWindow()
{
file.setFileName(":/jquery.min.js");
jQuery = file.readAll();
file.close();
QNetworkProxyFactory::setUseSystemConfiguration(true);
qsrand((uint)time.msec());
int randomValue = qrand() % 999;
view = new QWebView(this);
QUrl url
= QUrl::fromEncoded("http://blogsearch.google.com/blogsearch?hl=tr&ie=UTF-8&q=C%2B%2B&&output=rss");
url.addQueryItem("num", "1");
url.
addQueryItem("start" ,
QString::number(randomValue
));
view->load(url);
setCentralWidget(view);
}
void Window::setIcon()
{
icon.
addPixmap(QPixmap(":/images/heart.svg"));
trayIcon->setIcon(icon);
trayIcon->setVisible(true);
setWindowIcon(icon);
}
{
switch (reason) {
break;
showNormal();
break;
showMessage();
break;
default:
;
}
}
void Window::showMessage()
{
titleEdit
= new QLineEdit(tr
("Blog Search"));
bodyEdit->setPlainText(trUtf8("Blog okumak icin sag click + Maximize\n yapmaniz yeterli"));
trayIcon
->showMessage
(titleEdit
->text
(), bodyEdit
->toPlainText
(),
QSystemTrayIcon::Information,
1000);
}
void Window::createActions()
{
minimizeAction
= new QAction(tr
("Mi&nimize"),
this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
maximizeAction
= new QAction(tr
("Ma&ximize"),
this);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
restoreAction
= new QAction(tr
("&Restore"),
this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction
= new QAction(tr
("&Quit"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void Window::createTrayIcon()
{
trayIconMenu
= new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(maximizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
}
//main.cpp
#include <QtGui>
#include "window.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(systray);
QApplication app(argc, argv);
QApplication::setQuitOnLastWindowClosed(false);
Window box;
MainWindow window;
window.setParent(&box);
return app.exec();
}
//mainwindow.cpp
#include <QtGui>
class QWebView;
//! [1]
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
private:
QString jQuery;
QWebView *view;
};
//window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QDialog>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QLineEdit>
#include <QTextEdit>
class Window : public QDialog
{
Q_OBJECT
public:
Window();
private slots:
void setIcon();
void iconActivated(QSystemTrayIcon::ActivationReason reason);
void showMessage();
private:
void createActions();
void createTrayIcon();
QAction *minimizeAction;
QAction *maximizeAction;
QAction *restoreAction;
QAction *quitAction;
QLineEdit *titleEdit;
QTextEdit *bodyEdit;
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
};
#endif
//window.cpp
#include <QtGui>
#include <QtWebKit>
#include <QTime>
#include "window.h"
#include "mainwindow.h"
Window::Window()
{
createActions();
createTrayIcon();
setIcon();
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
setWindowTitle(tr("Blog Search"));
resize(600, 600);
}
MainWindow::MainWindow()
{
QFile file;
file.setFileName(":/jquery.min.js");
file.open(QIODevice::ReadOnly);
jQuery = file.readAll();
file.close();
QNetworkProxyFactory::setUseSystemConfiguration(true);
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
int randomValue = qrand() % 999;
view = new QWebView(this);
QUrl url = QUrl::fromEncoded("http://blogsearch.google.com/blogsearch?hl=tr&ie=UTF-8&q=C%2B%2B&&output=rss");
url.addQueryItem("num", "1");
url.addQueryItem("start" ,QString::number(randomValue));
view->load(url);
setCentralWidget(view);
}
void Window::setIcon()
{
QIcon icon;
icon.addPixmap(QPixmap(":/images/heart.svg"));
trayIcon->setIcon(icon);
trayIcon->setVisible(true);
setWindowIcon(icon);
}
void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
break;
case QSystemTrayIcon::DoubleClick:
showNormal();
break;
case QSystemTrayIcon::MiddleClick:
showMessage();
break;
default:
;
}
}
void Window::showMessage()
{
titleEdit = new QLineEdit(tr("Blog Search"));
bodyEdit = new QTextEdit;
bodyEdit->setPlainText(trUtf8("Blog okumak icin sag click + Maximize\n yapmaniz yeterli"));
trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), QSystemTrayIcon::Information,
1000);
}
void Window::createActions()
{
minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
maximizeAction = new QAction(tr("Ma&ximize"), this);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void Window::createTrayIcon()
{
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(maximizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
}
To copy to clipboard, switch view to plain text mode
Bookmarks