Esempio n. 1
0
void QMainWidget::createTrayIcon()
{
    QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
    QMenu *menu = new QMenu(this);
    QAction *windowAction = new QAction("Controller Window", this);
    QAction *quitAction = new QAction("Shutdown xboxToVJoy", this);
    
    enableAction = new QAction("Disable", this);
    connect(enableAction, SIGNAL(triggered()), this, SLOT(toggleEnabled()));
    
    connect(windowAction, SIGNAL(triggered()), this, SLOT(showControllerWindow()));
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    
    menu->addAction(windowAction);
    menu->addSeparator();
    menu->addAction(enableAction);
    menu->addSeparator();
    menu->addAction(quitAction);
    trayIcon->setContextMenu(menu);
    
    QIcon icon(":/icons/icon.png");
    trayIcon->setIcon(icon);
    
    trayIcon->show();
}
Esempio n. 2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowIcon(QIcon(":icons/icon.png"));
    setWindowTitle("quickly translate");
    QSystemTrayIcon * trayIcon = new QSystemTrayIcon(this);
    mNetManager = new QNetworkAccessManager(this);
    mLangageModel = new LanguageModel;

    trayIcon->setIcon(QIcon(":icons/icon.png"));

    trayIcon->setContextMenu(ui->menuFile);
    trayIcon->show();

    ui->dockWidget->hide();
    ui->sourceComboBox->setModel(mLangageModel);
    ui->targetComboBox->setModel(mLangageModel);

    QDesktopWidget * desktop = new QDesktopWidget;

    QPoint startPos = QPoint(desktop->geometry().bottomRight() );
    QPoint finalPos = desktop->geometry().center() - QPoint(width()/2,height()/2);

    move(finalPos);
    connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
    connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(exit()));
    connect(ui->translateButton,SIGNAL(clicked()),this,SLOT(translate()));
    connect(ui->sourceTextEdit,SIGNAL(returnPressed()),this,SLOT(translate()));
    connect(ui->swapButton,SIGNAL(clicked()),this,SLOT(swapLangages()));

    connect(ui->actionCopy,SIGNAL(triggered()),this,SLOT(copy()));
    connect(ui->actionCut,SIGNAL(triggered()),this,SLOT(cut()));
    connect(ui->actionPast,SIGNAL(triggered()),this,SLOT(past()));
    connect(ui->actionPreferences,SIGNAL(triggered()),this,SLOT(showPreferences()));
    connect(ui->actionAboutQt,SIGNAL(triggered()),this,SLOT(showAboutQt()));
    connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
    connect(ui->actionTTS,SIGNAL(triggered()),this,SLOT(showTextTTS()));


    connect(ui->sourceSoundButton,SIGNAL(clicked()),this,SLOT(textToSpeak()));
    connect(ui->targetSoundButton,SIGNAL(clicked()),this,SLOT(textToSpeak()));


    //    mPropertyAnimation  = new QPropertyAnimation(this, "pos");
    //    mPropertyAnimation->setDuration(800);
    //    mPropertyAnimation->setStartValue(startPos);
    //    mPropertyAnimation->setEndValue(finalPos);


    //load default langage

    QSettings settings;
    QString sourceId = settings.value("source").toString();
    QString targetId = settings.value("target").toString();
    ui->sourceComboBox->setCurrentIndex(mLangageModel->findLangageId(sourceId));
    ui->targetComboBox->setCurrentIndex(mLangageModel->findLangageId(targetId));

}
static PyObject *meth_QSystemTrayIcon_setContextMenu(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QMenu * a0;
        PyObject *a0Keep;
        QSystemTrayIcon *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B@J8", &sipSelf, sipType_QSystemTrayIcon, &sipCpp, &a0Keep, sipType_QMenu, &a0))
        {
            Py_BEGIN_ALLOW_THREADS
            sipCpp->setContextMenu(a0);
            Py_END_ALLOW_THREADS

            sipKeepReference(sipSelf, -60, a0Keep);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QSystemTrayIcon, sipName_setContextMenu, NULL);

    return NULL;
}
Esempio n. 4
0
int main(int argv, char **args)
{
	QApplication app(argv, args);
	app.setApplicationName("Munt mt32emu-qt");
	app.setQuitOnLastWindowClosed(false);

	QProcessEnvironment::systemEnvironment().insert("PA_ALSA_PLUGHW", "1");

	Master *master = Master::getInstance();
	QSystemTrayIcon *trayIcon = NULL;
	if (QSystemTrayIcon::isSystemTrayAvailable()) {
		trayIcon = new QSystemTrayIcon(QIcon(":/images/note.gif"));
		trayIcon->setToolTip("Munt: MT-32 Emulator");
		trayIcon->show();
		master->setTrayIcon(trayIcon);
	}
	MainWindow mainWindow(master);
	if (trayIcon == NULL || !master->getSettings()->value("Master/startIconized", "0").toBool()) mainWindow.show();
	master->startPinnedSynthRoute();
	master->startMidiProcessing();
	master->processCommandLine(app.arguments());
	app.exec();
	master->setTrayIcon(NULL);
	delete trayIcon;
	return 0;
}
Esempio n. 5
0
	void CNotificationManager::showStateNotificationBySender(libnutcommon::DeviceState state) {
		if (!m_NotificationsEnabled)
			return;

		CUIDevice * uiDevice = qobject_cast<CUIDevice *>(sender());
		if (!uiDevice)
			return;

		QString message;
		switch (state) {
		case libnutcommon::DeviceState::UP:
			message = tr("%2 is now up and running on network: %1")
				.arg(currentNetwork(uiDevice->device()));
			break;
		case libnutcommon::DeviceState::UNCONFIGURED:
			message = tr("%2 got carrier (to network: %1) but needs configuration.\n\nClick here to open the device details.")
				.arg(currentNetwork(uiDevice->device()));
			break;
		case libnutcommon::DeviceState::ACTIVATED:
			message = tr("%1 is now activated and waits for carrier.");
			break;
		case libnutcommon::DeviceState::DEACTIVATED:
			message = tr("%1 is now deactivated");
			break;
		default:
			return;
		}

		{
			QSystemTrayIcon * trayIcon = m_UIDeviceIcons.value(uiDevice, NULL);
			message = message.arg(trayIcon && trayIcon->isVisible() ? tr("Device") : uiDevice->device()->getName());
		}

		showDeviceMessage(QString(), message, uiDevice);
	}
Esempio n. 6
0
// Testing get/set functions
void tst_QSystemTrayIcon::showHide()
{
    QSystemTrayIcon icon;
    icon.setIcon(QIcon("icons/icon.png"));
    icon.show();
    icon.setIcon(QIcon("icons/icon.png"));
    icon.hide();
}
Esempio n. 7
0
/**
 * @brief Send a popup through Growl.
 * @param icon The icon inside the notification. Currently ignored.
 * @param timeout The time in ms to show the notification.
 * @param title The title displayed inside the notification.
 * @param message The message displayed inside the notification.
 */
void NotifyByPopupGrowl::popup( const QPixmap *icon, int timeout,
                                const QString &title, const QString &message )
{
  Q_UNUSED( icon );

  QSystemTrayIcon i;
  i.show();
  i.showMessage( title, message,
                 QSystemTrayIcon::Information, timeout );
  i.hide();
}
Esempio n. 8
0
TrayIconManager::TrayIconManager(QMainWindow* p_main)
{
    QMenu *trayMenu = new QMenu(p_main);
    trayMenu->addAction(new QAction("Dodaj wpis...", p_main)); // dummy action
    trayMenu->addSeparator();
    trayMenu->addAction(new QAction("Drukuj...", p_main)); // dummy action
    // set up and show the system tray icon
    QSystemTrayIcon *trayIcon = new QSystemTrayIcon(p_main);
    trayIcon->setIcon(QIcon("heart.ico"));
    trayIcon->setContextMenu(trayMenu);
    trayIcon->show();
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
#ifdef WIN32
	redirectCout();
#endif

    // If there is a set up white list and the
    // user is not in the white list then we need
    // to simply close this program down.  Otherwise
    // show the interface to the user.
    if (doesWhiteListExist())
    {
        cout << "White list exists" << endl;
        if (!isUserInWhiteList())
        {
            cout << getUserName() << " doesn't exist in white list. Program terminating."<< endl;
            exit(0);
            return 0;
        }
        else
        {
            cout << getUserName() << " is in white list."<< endl;
        }
    }
    else
    {
        cout << "White list does not exist." << endl;
    }

	int tray_tries = 30;
	int available;
	StatusUpdate *status;
	QApplication app(argc, argv);
    QSystemTrayIcon *trayIcon;
	QIcon icon(":images/disconnect.svg");
	available = QSystemTrayIcon::isSystemTrayAvailable();
	while(!available)
	{
		sleep(1);
		tray_tries--;
		if(tray_tries <= 0)
		{
			QMessageBox::critical(NULL, QObject::tr("System Tray"), QObject::tr("The system tray is not supported on your system."));
			return -1;
		}
		available = QSystemTrayIcon::isSystemTrayAvailable();
	}
    trayIcon = new QSystemTrayIcon(NULL);
    trayIcon->setIcon(icon);
    trayIcon->show();
    status = new StatusUpdate(trayIcon);
	return app.exec();
}
Esempio n. 10
0
void tst_QSystemTrayIcon::lastWindowClosed()
{
    QSignalSpy spy(qApp, SIGNAL(lastWindowClosed()));
    QWidget window;
    QSystemTrayIcon icon;
    icon.setIcon(QIcon("whatever.png"));
    icon.show();
    window.show();
    QTimer::singleShot(2500, &window, SLOT(close()));
    QTimer::singleShot(20000, qApp, SLOT(quit())); // in case the test fails
    qApp->exec();
    QVERIFY(spy.count() == 1);
}
Esempio n. 11
0
// Testing get/set functions
void tst_QSystemTrayIcon::getSetCheck()
{
    QSystemTrayIcon icon;
    QCOMPARE(true, icon.toolTip().isEmpty());
    icon.setToolTip("testToolTip");
    QCOMPARE(true, "testToolTip" == icon.toolTip());

    QCOMPARE(true, icon.icon().isNull());
    icon.setIcon(QIcon("icons/icon.png"));
    QCOMPARE(false, icon.icon().isNull());

    QMenu menu;
    QCOMPARE(true, icon.contextMenu() == 0);
    icon.setContextMenu(&menu);
    QCOMPARE(false, icon.contextMenu() == 0);
}
static PyObject *meth_QSystemTrayIcon_contextMenu(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QSystemTrayIcon *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QSystemTrayIcon, &sipCpp))
        {
            QMenu *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->contextMenu();
            Py_END_ALLOW_THREADS

            return sipConvertFromType(sipRes,sipType_QMenu,NULL);
        }
    }
Esempio n. 13
0
bool QSystemTrayIconSys::winEvent( MSG *m, long *result )
{
    switch(m->message) {
    case WM_CREATE:
        SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams);
        break;

    case MYWM_NOTIFYICON:
        {
            QPoint gpos = QCursor::pos();

            switch (m->lParam) {
            case WM_LBUTTONUP:
                if (ignoreNextMouseRelease)
                    ignoreNextMouseRelease = false;
                else
                    emit q->activated(QSystemTrayIcon::Trigger);
                break;

            case WM_LBUTTONDBLCLK:
                ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse 
                                               // release we must ignore it
                emit q->activated(QSystemTrayIcon::DoubleClick);
                break;

            case WM_RBUTTONUP:
                if (q->contextMenu()) {
                    q->contextMenu()->popup(gpos);

                    // We must ensure that the popup menu doesn't show up behind the task bar.
                    QRect desktopRect = qApp->desktop()->availableGeometry();
                    int maxY = desktopRect.y() + desktopRect.height() - q->contextMenu()->height();
                    if (gpos.y() > maxY) {
                        gpos.ry() = maxY;
                        q->contextMenu()->move(gpos);
                    }
                }
                emit q->activated(QSystemTrayIcon::Context);
                break;

            case WM_MBUTTONUP:
                emit q->activated(QSystemTrayIcon::MiddleClick);
                break;

            default:
                break;
            }
            break;
        }
    default:
        return QWidget::winEvent(m, result);
    }
    return 0;
}
Esempio n. 14
0
	void CNotificationManager::registerUIDevice(CUIDevice * uiDevice) {
		QSystemTrayIcon * newTrayIcon = new QSystemTrayIcon(this);
		m_UIDeviceIcons.insert(uiDevice, newTrayIcon);
		
		newTrayIcon->setContextMenu(uiDevice->deviceMenu());
		m_MainIcon->contextMenu()->insertMenu(m_InsertMarker, uiDevice->deviceMenu());
		
		updateDeviceIcon(uiDevice);
		setIconVisible(uiDevice->m_ShowTrayIcon, uiDevice);
		
		connect(uiDevice, SIGNAL(showNotificationRequested(libnutcommon::DeviceState)),
			this, SLOT(showStateNotification(libnutcommon::DeviceState)));
		connect(uiDevice, SIGNAL(updateTrayIconRequested(libnutcommon::DeviceState)),
			this, SLOT(updateDeviceIcon()));
		connect(uiDevice, SIGNAL(showTrayIconRequested(bool)),
			this, SLOT(setIconVisible(bool)));
		
		connect(newTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
			this, SLOT(handleDeviceIconActivated(QSystemTrayIcon::ActivationReason)));
	}
Esempio n. 15
0
	void CNotificationManager::registerUIDevice(CUIDevice * uiDevice) {
		QSystemTrayIcon * newTrayIcon = new QSystemTrayIcon(this);
		m_UIDeviceIcons.insert(uiDevice, newTrayIcon);

		newTrayIcon->setContextMenu(uiDevice->deviceMenu());
		m_MainIcon->contextMenu()->insertMenu(m_InsertMarker, uiDevice->deviceMenu());

		updateDeviceIcon(uiDevice);
		setIconVisible(uiDevice->m_ShowTrayIcon, uiDevice);

		connect(uiDevice, &CUIDevice::showNotificationRequested,
			this, &CNotificationManager::showStateNotificationBySender);
		connect(uiDevice, &CUIDevice::updateTrayIconRequested,
			this, &CNotificationManager::updateDeviceIconBySender);
		connect(uiDevice, &CUIDevice::showTrayIconRequested,
			this, &CNotificationManager::setIconVisibleBySender);

		connect(newTrayIcon, &QSystemTrayIcon::activated,
			this, &CNotificationManager::handleDeviceIconActivated);
	}
Esempio n. 16
0
int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    KAboutData about("kdeconnect-cli",
                     i18n("KDE Connect Indicator"),
                     QStringLiteral(KDECONNECT_VERSION_STRING),
                     i18n("KDE Connect Indicator tool"),
                     KAboutLicense::GPL,
                     i18n("(C) 2016 Aleix Pol Gonzalez"));
    KAboutData::setApplicationData(about);

    DevicesModel model;
    model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired);

    QMenu menu;
    auto configure = menu.addAction(i18n("Configure..."));
    QObject::connect(configure, &QAction::triggered, configure, [](){
        QProcess::startDetached("kcmshell5", {"kdeconnect"});
    });

    QSystemTrayIcon systray;
    systray.setIcon(QIcon::fromTheme("kdeconnect"));
    systray.setContextMenu(&menu);
    systray.setVisible(true);

    QObject::connect(&model, &DevicesModel::rowsInserted, &model, [&menu, &model](const QModelIndex& /*parent*/, int first, int last) {
        for (int i=first; i<=last; ++i) {
            DeviceDbusInterface* device = model.getDevice(i);
            auto indicator = new DeviceIndicator(device);
            QObject::connect(device, &DeviceDbusInterface::destroyed, indicator, &QObject::deleteLater);

            menu.addMenu(indicator);
        }
    });

    QObject::connect(&model, &DevicesModel::rowsChanged, &model, [&systray, &model]() {
        systray.setToolTip(i18np("%1 device connected", "%1 devices connected", model.rowCount()));
    });

    return app.exec();
}
Esempio n. 17
0
	void CNotificationManager::showMessage(QString title, QString message, QObject * reciever, const char * slot, CUIDevice * uiDevice) {
		if (!m_NotificationsEnabled)
			return;
		
		QString titleResult = tr("QNUT");
		QSystemTrayIcon * trayIcon;
		if (uiDevice && m_UIDeviceIcons.contains(uiDevice) && m_UIDeviceIcons[uiDevice]->isVisible()) {
			trayIcon = m_UIDeviceIcons[uiDevice];
			titleResult += " (" + uiDevice->device()->getName() + ')';
		}
		else
			trayIcon = m_MainIcon;
		
		if (!title.isEmpty())
			titleResult += " - " + title;
		
		disconnect(trayIcon, SIGNAL(messageClicked()), NULL, NULL);
		if (reciever)
			connect(trayIcon, SIGNAL(messageClicked()), reciever, slot);
		trayIcon->showMessage(titleResult, message, QSystemTrayIcon::Information, 4000);
	}
Esempio n. 18
0
void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd)
{
    tnd.uFlags |= NIF_MESSAGE | NIF_ICON | NIF_TIP;
    tnd.uCallbackMessage = MYWM_NOTIFYICON;
    tnd.hIcon = hIcon;
    QString tip = q->toolTip();

    if (!tip.isNull()) {
        tip = tip.left(maxTipLength - 1) + QChar();
        memcpy(tnd.szTip, tip.utf16(), qMin(tip.length() + 1, maxTipLength) * sizeof(wchar_t));
    }
}
Esempio n. 19
0
File: main.cpp Progetto: Abbath/P
/*!
 * \brief main
 * \param argc
 * \param argv
 * \return 
 */
int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    
    a.setQuitOnLastWindowClosed(false);
    a.processEvents();
    
    Dialog *d = new Dialog;
    d->setWindowIcon(QIcon(":/ops.png"));
    d->show();
    
    QSystemTrayIcon * qsti = new QSystemTrayIcon(d);
    QMenu *trayIconMenu;
    QAction *minimizeAction;
    QAction *restoreAction;
    QAction *quitAction;
    
    minimizeAction = new QAction("Minimize", d);
    restoreAction = new QAction("Restore", d);
    quitAction = new QAction("Quit", d);
    
    QObject::connect(minimizeAction, SIGNAL(triggered()), d, SLOT(hide()));
    QObject::connect(restoreAction, SIGNAL(triggered()), d,SLOT(showNormal()));
    QObject::connect(quitAction, SIGNAL(triggered()), &a, SLOT(quit()));
    QObject::connect(d, SIGNAL(destroyed()), &a, SLOT(quit()));
    
    trayIconMenu = new QMenu(d);
    trayIconMenu->addAction (minimizeAction);
    trayIconMenu->addAction (restoreAction);
    trayIconMenu->addAction (quitAction);
    
    qsti->setContextMenu(trayIconMenu);
    qsti->setIcon(QIcon(":/ops.png"));
    qsti->show();
    
    QObject::connect(qsti, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), d, SLOT(trayHandle(QSystemTrayIcon::ActivationReason)));
    
    return a.exec();
}
Esempio n. 20
0
ADM_qtray::ADM_qtray(const void* parent) : ADM_tray(parent)
{
	_parent = parent;
	lastIcon = 0;
	maxIcons = 12;

	pixmap = new QIcon[maxIcons];
	pixmap[0] = QIcon(QPixmap(xpm_film1));
	pixmap[1] = QIcon(QPixmap(xpm_film3));
	pixmap[2] = QIcon(QPixmap(xpm_film5));
	pixmap[3] = QIcon(QPixmap(xpm_film7));
	pixmap[4] = QIcon(QPixmap(xpm_film9));
	pixmap[5] = QIcon(QPixmap(xpm_film11));
	pixmap[6] = QIcon(QPixmap(xpm_film13));
	pixmap[7] = QIcon(QPixmap(xpm_film15));
	pixmap[8] = QIcon(QPixmap(xpm_film17));
	pixmap[9] = QIcon(QPixmap(xpm_film19));
	pixmap[10] = QIcon(QPixmap(xpm_film21));
	pixmap[11] = QIcon(QPixmap(xpm_film23));

	signalReceiver = new ADM_qtray_signalReceiver();
	signalReceiver->parent = (QDialog*)parent;
	QSystemTrayIcon* trayIcon = new QSystemTrayIcon(pixmap[0], (QObject*)parent);

	sys = trayIcon;

	trayIcon->setToolTip("Avidemux");

	openAction = new QAction(QT_TR_NOOP("Open Avidemux"), (QObject*)parent);
	QObject::connect(openAction, SIGNAL(triggered()), signalReceiver, SLOT(restore()));
	QObject::connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), signalReceiver, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

	trayIconMenu = new QMenu((QWidget*)parent);
	trayIconMenu->addAction(openAction);

	trayIcon->setContextMenu(trayIconMenu);
	trayIcon->show();
}
Esempio n. 21
0
void QSystemTrayIconSys::createIcon()
{
    hIcon = 0;
    QIcon icon = q->icon();
    if (icon.isNull())
        return;

    //const QSize preferredSize(GetSystemMetrics(SM_CXSMICON) * 2, GetSystemMetrics(SM_CYSMICON) * 2);
    const QSize preferredSize(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
    QPixmap pm = icon.pixmap(preferredSize);
    if (pm.isNull())
        return;

    hIcon = pm.toWinHICON();
}
Esempio n. 22
0
File: main.cpp Progetto: realnc/munt
int main(int argv, char **args) {
	QApplication app(argv, args);
	app.setApplicationName("Munt mt32emu-qt");
	app.setQuitOnLastWindowClosed(false);
	{
		Master master;
		QSystemTrayIcon *trayIcon = NULL;
		if (QSystemTrayIcon::isSystemTrayAvailable()) {
			trayIcon = new QSystemTrayIcon(QIcon(":/images/note.gif"));
			trayIcon->setToolTip("Munt: MT-32 Emulator");
			trayIcon->show();
			master.setTrayIcon(trayIcon);
		}
		MainWindow mainWindow(&master);
		if (trayIcon == NULL || !master.getSettings()->value("Master/startIconized", false).toBool()) mainWindow.show();
		if (argv > 1) master.processCommandLine(app.arguments());
		master.startPinnedSynthRoute();
		master.startMidiProcessing();
		app.exec();
		master.setTrayIcon(NULL);
		delete trayIcon;
	}
	return 0;
}
Esempio n. 23
0
void QSystemTrayIconSys::createIcon()
{
    hIcon = 0;
    QIcon icon = q->icon();
    if (icon.isNull())
        return;

    const int iconSizeX = GetSystemMetrics(SM_CXSMICON);
    const int iconSizeY = GetSystemMetrics(SM_CYSMICON);
    QSize size = icon.actualSize(QSize(iconSizeX, iconSizeY));
    QPixmap pm = icon.pixmap(size);
    if (pm.isNull())
        return;

    hIcon = pm.toWinHICON();
}
Esempio n. 24
0
void QSystemTrayIconSys::setIconContentsA(NOTIFYICONDATAA &tnd)
{
    tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    tnd.uCallbackMessage = MYWM_NOTIFYICON;
    tnd.hIcon = hIcon;
    QString tip = q->toolTip();

    if (!tip.isNull()) {
        // Tip is limited to maxTipLength - NULL; lstrcpyn appends a NULL terminator.
        tip = tip.left(maxTipLength - 1) + QChar();
#if defined(Q_OS_WINCE)
        strncpy(tnd.szTip, tip.toLocal8Bit().constData(), qMin(tip.length()+1, maxTipLength));
#else
        lstrcpynA(tnd.szTip, tip.toLocal8Bit().constData(), qMin(tip.length()+1, maxTipLength));
#endif
    }
}
Esempio n. 25
0
void QSystemTrayIconSys::setIconContentsW(NOTIFYICONDATAW &tnd)
{
    tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    tnd.uCallbackMessage = MYWM_NOTIFYICON;
    tnd.hIcon = hIcon;
    QString tip = q->toolTip();

    if (!tip.isNull()) {
        // Tip is limited to maxTipLength - NULL; lstrcpyn appends a NULL terminator.
        tip = tip.left(maxTipLength - 1) + QChar();
#if defined(Q_OS_WINCE)
        wcsncpy(tnd.szTip, reinterpret_cast<const wchar_t *> (tip.utf16()), qMin(tip.length()+1, maxTipLength));
#else
        lstrcpynW(tnd.szTip, (TCHAR*)tip.utf16(), qMin(tip.length()+1, maxTipLength));
#endif
    }
}
Esempio n. 26
0
void TrayPrivate::refreshIcon()
{
    //Note: the icons::getIcon chooses the right icon from list of possible candidates
    // -> we need to refresh the icon in case of icon theme change
    mTrayIcon.setIcon(icons::getIcon(mIconCurrent));
}
bool QSystemTrayIconSys::winEvent( MSG *m, long *result )
{
    switch(m->message) {
    case WM_CREATE:
#ifdef GWLP_USERDATA
        SetWindowLongPtr(winId(), GWLP_USERDATA, (LONG_PTR)((CREATESTRUCTW*)m->lParam)->lpCreateParams);
#else
        SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams);
#endif
        break;

    case WM_DRAWITEM:
        return iconDrawItem((LPDRAWITEMSTRUCT)m->lParam);

    case MYWM_NOTIFYICON:
    {
        RECT r;
        GetWindowRect(winId(), &r);
        QEvent *e = 0;
        Qt::KeyboardModifiers keys = QApplication::keyboardModifiers();
        QPoint gpos = QCursor::pos();

        switch (m->lParam) {
        case WM_LBUTTONUP:
            if (ignoreNextMouseRelease)
                ignoreNextMouseRelease = false;
            else
                emit q->activated(QSystemTrayIcon::Trigger);
            break;

        case WM_LBUTTONDBLCLK:
            ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse
            // release we must ignore it
            emit q->activated(QSystemTrayIcon::DoubleClick);
            break;

        case WM_RBUTTONUP:
            if (q->contextMenu()) {
                q->contextMenu()->popup(gpos);
#if defined(Q_WS_WINCE)
                // We must ensure that the popup menu doesn't show up behind the task bar.
                QRect desktopRect = qApp->desktop()->availableGeometry();
                int maxY = desktopRect.y() + desktopRect.height() - q->contextMenu()->height();
                if (gpos.y() > maxY) {
                    gpos.ry() = maxY;
                    q->contextMenu()->move(gpos);
                }
#endif
                q->contextMenu()->activateWindow();
                //Must be activated for proper keyboardfocus and menu closing on windows:
            }
            emit q->activated(QSystemTrayIcon::Context);
            break;

#if !defined(Q_WS_WINCE)
        case NIN_BALLOONUSERCLICK:
            emit q->messageClicked();
            break;
#endif

        case WM_MBUTTONUP:
            emit q->activated(QSystemTrayIcon::MiddleClick);
            break;
        default:
            break;
        }
        if (e) {
            bool res = QApplication::sendEvent(q, e);
            delete e;
            return res;
        }
        break;
    }
    default:
        if (m->message == MYWM_TASKBARCREATED)
            trayMessage(NIM_ADD);
        else
            return QWidget::winEvent(m, result);
        break;
    }
    return 0;
}
Esempio n. 28
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    const QString app_name("timecop");
    const QString app_version("1.1");
    const QString app_settings_dir(QDir::home().filePath(".timecop"));

    app.setOrganizationName("Daimler AG RD-DDA");
    app.setApplicationName(app_name);

    QSettings::setDefaultFormat(QSettings::IniFormat);
    QSettings::setPath(QSettings::IniFormat,
                       QSettings::UserScope,
                       app_settings_dir);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    QObject *root = 0;
    QWidget *rootWindow = 0;
    SystrayHelper systrayHelper;
    engine.rootContext()->setContextProperty("systrayHelper", &systrayHelper);

    engine.rootContext()->setContextProperty("app_name",  app_name);
    engine.rootContext()->setContextProperty("app_version",  app_version);
    engine.rootContext()->setContextProperty("app_settings_dir",  app_settings_dir);


    if (engine.rootObjects().size() > 0)
    {
        root = engine.rootObjects().at(0);
        systrayHelper.setRootWindow(root);
        if(root->isWindowType()){
            rootWindow = qobject_cast<QWidget*>(root);

            QApplication::setQuitOnLastWindowClosed(false);

            QAction *minimizeAction = new QAction(QObject::tr("Mi&nimize"), rootWindow);
            rootWindow->connect(minimizeAction, SIGNAL(triggered()), root, SLOT(hide()));
            QAction *maximizeAction = new QAction(QObject::tr("Ma&ximize"), rootWindow);
            rootWindow->connect(maximizeAction, SIGNAL(triggered()), root, SLOT(showMaximized()));
            QAction *restoreAction = new QAction(QObject::tr("&Restore"), rootWindow);
            rootWindow->connect(restoreAction, SIGNAL(triggered()), root, SLOT(showNormal()));
            QAction *quitAction = new QAction(QObject::tr("&Quit"), rootWindow);
            rootWindow->connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));

            QMenu *trayIconMenu = new QMenu(rootWindow);
            trayIconMenu->addAction(minimizeAction);
            trayIconMenu->addAction(maximizeAction);
            trayIconMenu->addAction(restoreAction);
            trayIconMenu->addSeparator();
            trayIconMenu->addAction(quitAction);

            QSystemTrayIcon *trayIcon = new QSystemTrayIcon(rootWindow);
            QIcon icon(":/trayicon.png");
            icon.setIsMask(true);
            //trayIcon->setContextMenu(trayIconMenu);
            trayIcon->setIcon(icon);
            trayIcon->setToolTip("Click to open");
            trayIcon->setVisible(true);
            systrayHelper.setTrayIcon(trayIcon);
            QObject::connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), &systrayHelper, SLOT(activatedSystray(QSystemTrayIcon::ActivationReason)));

            trayIcon->show();
        }

    }

    return app.exec();
}
Esempio n. 29
0
bool QSystemTrayIconSys::winEvent( MSG *m, long *result )
{
    switch(m->message) {
    case MYWM_NOTIFYICON:
        {
            int message = 0;
            QPoint gpos;

            if (version == NOTIFYICON_VERSION_4) {
                Q_ASSERT(q_uNOTIFYICONID == HIWORD(m->lParam));
                message = LOWORD(m->lParam);
                gpos = QPoint(GET_X_LPARAM(m->wParam), GET_Y_LPARAM(m->wParam));
            } else {
                Q_ASSERT(q_uNOTIFYICONID == m->wParam);
                message = m->lParam;
                gpos = QCursor::pos();
            }

            switch (message) {
            case NIN_SELECT:
            case NIN_KEYSELECT:
                if (ignoreNextMouseRelease)
                    ignoreNextMouseRelease = false;
                else 
                    emit q->activated(QSystemTrayIcon::Trigger);
                break;

            case WM_LBUTTONDBLCLK:
                ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse 
                                               // release we must ignore it
                emit q->activated(QSystemTrayIcon::DoubleClick);
                break;

            case WM_CONTEXTMENU:
                if (q->contextMenu()) {
                    q->contextMenu()->popup(gpos);
                    q->contextMenu()->activateWindow();
                }
                emit q->activated(QSystemTrayIcon::Context);
                break;

            case NIN_BALLOONUSERCLICK:
                emit q->messageClicked();
                break;

            case WM_MBUTTONUP:
                emit q->activated(QSystemTrayIcon::MiddleClick);
                break;

            default:
                break;
            }
            break;
        }
    default:
        if (m->message == MYWM_TASKBARCREATED)
            trayMessage(NIM_ADD);
        else
            return QWidget::winEvent(m, result);
        break;
    }
    return 0;
}
Esempio n. 30
0
// Testing get/set functions
void tst_QSystemTrayIcon::showMessage()
{
    QSystemTrayIcon icon;
    icon.setIcon(QIcon("icons/icon.png"));

    icon.showMessage("Title", "Messagecontents");
    icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
    icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Warning);
    icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Critical);

    icon.show();
    icon.showMessage("Title", "Messagecontents");
    icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
    icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Warning);
    icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Critical);
}