Example #1
0
MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        proxy(new QSortFilterProxyModel(parent)),
        model(new QStandardItemModel(0, 3, parent))
{
    // Set the window style.
    Qt::WindowFlags flags = windowFlags();
    setWindowFlags(flags | Qt::WindowStaysOnTopHint | Qt::ToolTip);

    // Center window.
    QDesktopWidget *desktop = QApplication::desktop();
    int width = desktop->width() * 0.6;
    int height = desktop->height() * 0.6;
    setFixedSize(width, height);
    move((desktop->width() - width) / 2, (desktop->height() - height) / 2);

    // Set up system tray.
    trayIconMenu = new QMenu(this);
    aboutAction = new QAction(tr("&About"), this);
    quitAction = new QAction(tr("&Quit"), this);
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutMain()));
    connect(quitAction, SIGNAL(triggered()), this, SLOT(quitMain()));
    trayIconMenu->addAction(aboutAction);
    trayIconMenu->addAction(quitAction);
    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setContextMenu(trayIconMenu);
    trayIcon->setToolTip(QString("QuickWin"));
    trayIcon->setIcon(QIcon("icon.png"));
    trayIcon->show();

    // Set up UI items.
    ui->setupUi(this);
    proxy->setSourceModel(model);
    ui->winView->setModel(proxy);
    proxy->setFilterKeyColumn(1);
    ui->winView->setSortingEnabled(true);
    ui->winView->sortByColumn(0, Qt::AscendingOrder);
    ui->winView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Number"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Title"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Executable"));
    ui->winView->header()->resizeSection(0, width * 0.08);
    ui->winView->header()->resizeSection(1, width * 0.7);

    connect(ui->cmdText, SIGNAL(returnPressed()),
            this,SLOT(onTextEnter()));
    connect(ui->cmdText, SIGNAL(textChanged(const QString &)),
            this, SLOT(onTextChanged(const QString &)));
    connect(ui->winView, SIGNAL(activated(QModelIndex)),
            this, SLOT(onWitemActivate(QModelIndex)));

    // Register system-wide hotkey.
    HWND hwnd = (HWND)this->winId();
    RegisterHotKey(hwnd, 100, MOD_CONTROL | MOD_ALT, VK_SPACE);

    updateWinList();
}
Example #2
0
void MainWindow::windowActivationChange(bool state) {
    if(state) {
        // Lost focus.
        hide();
    } else {
        // In focus.
        updateWinList();
        checkSavedWins();
        showMain();
    }
}
Example #3
0
WindowsModel::WindowsModel (QObject *parent)
    : QAbstractItemModel (parent)
    , CurrentDesktop_ (Util::XWrapper::Instance ().GetCurrentDesktop ())
    , ImageProvider_ (new TaskbarImageProvider (QIcon::fromTheme ("xorg")))
{
    auto& w = Util::XWrapper::Instance ();
    auto windows = w.GetWindows ();
    for (auto wid : windows)
        AddWindow (wid, w);

    connect (&w,
             SIGNAL (windowListChanged ()),
             this,
             SLOT (updateWinList ()));
    connect (&w,
             SIGNAL (activeWindowChanged ()),
             this,
             SLOT (updateActiveWindow ()));

    connect (&w,
             SIGNAL (windowNameChanged (ulong)),
             this,
             SLOT (updateWindowName (ulong)));
    connect (&w,
             SIGNAL (windowIconChanged (ulong)),
             this,
             SLOT (updateWindowIcon (ulong)));
    connect (&w,
             SIGNAL (windowStateChanged (ulong)),
             this,
             SLOT (updateWindowState (ulong)));
    connect (&w,
             SIGNAL (windowActionsChanged (ulong)),
             this,
             SLOT (updateWindowActions (ulong)));
    connect (&w,
             SIGNAL (windowDesktopChanged (ulong)),
             this,
             SLOT (updateWindowDesktop (ulong)));
    connect (&w,
             SIGNAL (desktopChanged ()),
             this,
             SLOT (updateCurrentDesktop ()));

    QHash<int, QByteArray> roleNames;
    roleNames [Role::WindowName] = "windowName";
    roleNames [Role::WindowID] = "windowID";
    roleNames [Role::IconGenID] = "iconGenID";
    roleNames [Role::IsCurrentDesktop] = "isCurrentDesktop";
    roleNames [Role::IsActiveWindow] = "isActiveWindow";
    roleNames [Role::IsMinimizedWindow] = "isMinimizedWindow";
    setRoleNames (roleNames);

    int eventBase, errorBase;
    if (XCompositeQueryExtension (w.GetDisplay (), &eventBase, &errorBase))
    {
        int major = 0, minor = 2;
        XCompositeQueryVersion (w.GetDisplay (), &major, &minor);

        if (major > 0 || minor >= 2)
            qDebug () << "all good, has NamePixmap";
    }
}