void MainWindow::keyPressEvent(QKeyEvent *event) { bool hide_win = (event->key() == Qt::Key_Escape); bool quit_app = false; SelMove mv = SELMOVE_NO; if(event->modifiers() && Qt::ControlModifier) { switch(event->key()) { case Qt::Key_H: mv = SELMOVE_TOP; break; case Qt::Key_L: mv = SELMOVE_BTM; break; case Qt::Key_K: mv = SELMOVE_UP; break; case Qt::Key_J: mv = SELMOVE_DWN; break; case Qt::Key_M: mv = SELMOVE_MID; break; case Qt::Key_C: hide_win = true; break; #ifndef QT_NO_DEBUG case Qt::Key_X: quit_app = true; break; #endif } } else { switch(event->key()) { case Qt::Key_Home: mv = SELMOVE_TOP; break; case Qt::Key_End: mv = SELMOVE_BTM; break; case Qt::Key_Up: mv = SELMOVE_UP; break; case Qt::Key_Down: mv = SELMOVE_DWN; break; } } moveSel(mv); if(hide_win) { hide(); } // TODO: Debug only! Remove later... if(quit_app) { quitMain(); } }
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(); }
qtSearchWindow::qtSearchWindow(std::string index_file, double restart_Probability, int pageRankSteps){ Restart_Probability = restart_Probability; PageRankSteps = pageRankSteps; PageParser* parser = new MDparser(); searchengine.add_parse_from_index_file(index_file, parser); wrongFormat = false; //title setWindowTitle("qtSearch"); // Overall layout overallLayout = new QHBoxLayout(); // //form to show the seach result //Layout displayResultLayout = new QVBoxLayout(); overallLayout->addLayout(displayResultLayout); //form resultNameList = new QListWidget(); displayResultLayout->addWidget(resultNameList); //display options showDetail = new QPushButton("Show Detailed Content!"); connect(showDetail, SIGNAL(clicked()), this, SLOT(showWebpageContents())); displayByFilenameslistButton = new QPushButton("Sort by Filenames"); connect(displayByFilenameslistButton, SIGNAL(clicked()), this, SLOT(displayByFilename())); displayByOutgoingLinksButton = new QPushButton("Sort by Outgoing Links"); connect(displayByOutgoingLinksButton, SIGNAL(clicked()), this, SLOT(displayByOutgoingLinks())); displayByIncomingLinksButton = new QPushButton("Sort by Incoming Links"); connect(displayByIncomingLinksButton, SIGNAL(clicked()), this, SLOT(displayByIncomingLinks())); displayByPageRankButton = new QPushButton("Sort by PageRank"); connect(displayByPageRankButton, SIGNAL(clicked()), this, SLOT(displayByPageRank())); displayResultLayout->addWidget(showDetail); displayResultLayout->addWidget(displayByFilenameslistButton); displayResultLayout->addWidget(displayByOutgoingLinksButton); displayResultLayout->addWidget(displayByIncomingLinksButton); displayResultLayout->addWidget(displayByPageRankButton); // //Search functionality section //Layout queryLayout = new QVBoxLayout(); overallLayout->addLayout(queryLayout); //Query Label queryLabel = new QLabel("What do you want to search?"); queryLayout->addWidget(queryLabel); //Query words input queryInput = new QLineEdit(); queryLayout->addWidget(queryInput); connect(queryInput, SIGNAL(returnPressed()), this, SLOT(query())); //search options singleOption = new QRadioButton("Let's do single word search!", this); andOption = new QRadioButton("Let's do <AND> search!", this); orOption = new QRadioButton("Let's do <OR> search!", this); singleOption->setChecked(true); queryLayout->addWidget(singleOption); queryLayout->addWidget(andOption); queryLayout->addWidget(orOption); //search button queryButtton = new QPushButton("Magic Search!"); connect(queryButtton, SIGNAL(clicked()), this, SLOT(query())); quitButton = new QPushButton("Quit Application"); queryLayout->addWidget(queryButtton); queryLayout->addWidget(quitButton); connect(quitButton, SIGNAL(clicked()), this, SLOT(quitMain())); //this is the section for subwindow detailedWindow = new QWidget(); webpageDetailedDisplayLayout = new QVBoxLayout(); contentDisplayLayout = new QVBoxLayout(); webpageDetailedDisplayLayout->addLayout(contentDisplayLayout); webpageDetailedNameLabel = new QLabel(); contentName = new QLabel("Content:"); content = new QTextEdit(); content->setReadOnly(true); contentDisplayLayout->addWidget(webpageDetailedNameLabel); contentDisplayLayout->addWidget(contentName); contentDisplayLayout->addWidget(content); webpageDetailedIncomingLabel = new QLabel("IncomingLinks of this page:"); webpageDetailedIncomingList = new QListWidget(); showdeatilDetail1 = new QPushButton("Show detail of this link!"); connect(showdeatilDetail1, SIGNAL(clicked()), this, SLOT(showdetail1())); webpageDetailedOutgoingLabel= new QLabel("OutgoingLinks of this page:"); webpageDetailedOutgoingList = new QListWidget(); showdeatilDetail2 = new QPushButton("Show detail of this link!"); connect(showdeatilDetail2, SIGNAL(clicked()), this, SLOT(showdetail2())); webpageDetailedDisplayLayout->addWidget(webpageDetailedIncomingLabel); webpageDetailedDisplayLayout->addWidget(webpageDetailedIncomingList); webpageDetailedDisplayLayout->addWidget(showdeatilDetail1); webpageDetailedDisplayLayout->addWidget(webpageDetailedOutgoingLabel); webpageDetailedDisplayLayout->addWidget(webpageDetailedOutgoingList); webpageDetailedDisplayLayout->addWidget(showdeatilDetail2); detailedDisplayByFilenamesButtom = new QPushButton("Sort by Filenames"); detailedDisplayByIncomingLinksButtom = new QPushButton("Sort by Incominglinks"); detailedDisplayByOutgoingLinkButtom = new QPushButton("Sort by Outgoinginglinks"); quit = new QPushButton("Close Window"); webpageDetailedDisplayLayout->addWidget(detailedDisplayByFilenamesButtom); webpageDetailedDisplayLayout->addWidget(detailedDisplayByIncomingLinksButtom); webpageDetailedDisplayLayout->addWidget(detailedDisplayByOutgoingLinkButtom); webpageDetailedDisplayLayout->addWidget(quit); connect(quit, SIGNAL(clicked()), this, SLOT(quitSub())); connect(detailedDisplayByFilenamesButtom, SIGNAL(clicked()), this, SLOT(detailedDisplayByFileNames())); connect(detailedDisplayByIncomingLinksButtom, SIGNAL(clicked()), this, SLOT(detailedDisplayByIncomingLinks())); connect(detailedDisplayByOutgoingLinkButtom, SIGNAL(clicked()), this, SLOT(detailedDisplayByOutgoingLinks())); detailedWindow->setLayout(webpageDetailedDisplayLayout); //Set overall layout setLayout(overallLayout); }