Пример #1
0
void MainGui::openDocumentation() {
	QDialog *help=new QDialog();
	help->setAttribute(Qt::WA_DeleteOnClose);
	Ui::HelpDialog ui;
	ui.setupUi(help);
	QString docDir = QCoreApplication::applicationDirPath();
	docDir.append("/../Resources/html");
	ui.tb->setSearchPaths(QStringList("/usr/share/qtpfsgui/html") << "/usr/local/share/qtpfsgui/html" << "./html" << docDir << "/Applications/qtpfsgui.app/Contents/Resources/html");
	ui.tb->setSource(QUrl("index.html"));
	help->show();
}
/*!
    \fn ViewerWidget::keyPressEvent(QKeyEvent *k)
    Handle all keyboard events. All events which are not handled trigger
    a help window.
 */
void ViewerWidget::keyPressEvent(QKeyEvent* k)
{
    QPoint middlepoint;

    switch (k->key())
    {
        // next image
        case Qt::Key_N:
        case Qt::Key_Right:
        case Qt::Key_Down:
        case Qt::Key_PageDown:
        case Qt::Key_Space:
            nextImage();
            break;

        // previous image
        case Qt::Key_P:
        case Qt::Key_Left:
        case Qt::Key_Up:
        case Qt::Key_PageUp:
            prevImage();
            break;

        // rotate image
        case Qt::Key_R:
            texture->rotate();
            downloadTex(texture);
            updateGL();
            break;

        // terminate image viewer
        case Qt::Key_Escape:
            // clean up: where does this have to be done?
            close();
            break;

        // full screen
        case Qt::Key_F:
            // according to QT documentation, showFullScreen() has some
            // serious issues on window managers that do not follow modern
            // post-ICCCM specifications
            if (isFullScreen())
            {
                texture->reset();
                showNormal();
            }
            else
            {
                texture->reset();
                showFullScreen();
            }
            break;

        // reset size and redraw
        case Qt::Key_Z:
            texture->reset();
            updateGL();
            break;

        // toggle permanent between "show next image" and "zoom" on mousewheel change
        case Qt::Key_C:
            if (wheelAction==zoomImage)
                wheelAction=changeImage;
            else
                wheelAction=zoomImage;
            break;

        // zoom	in
        case Qt::Key_Plus:
            middlepoint =  QPoint(width()/2,height()/2);
            if (texture->setSize( zoomsize ))
                downloadTex(texture); //load full resolution image

            zoom(-1, middlepoint, zoomfactor_keyboard);
            break;

        // zoom out
        case Qt::Key_Minus:
            middlepoint =  QPoint(width()/2,height()/2);
            if (texture->setSize( zoomsize ))
                downloadTex(texture); //load full resolution image

            zoom(1, middlepoint, zoomfactor_keyboard);
            break;

        // zoom to original size
        case Qt::Key_O:
            texture->zoomToOriginal();
            updateGL();
            break;

        // toggle temorarily between "show next image" and "zoom" on mousewheel change
        case Qt::Key_Control:
            if (wheelAction == zoomImage)
            {
                //scrollwheel changes to the next image
                wheelAction = changeImage;
            }
            else
            {
                //scrollwheel does zoom
                wheelAction = zoomImage;
                setCursor (zoomCursor);
                timerMouseMove.stop();
            }
            break;

        //do noting, don't trigger the help dialog
        case Qt::Key_Shift:
            break;

        //key is not bound to any action, therefore show help dialog to enlighten the user
        default:
            QPointer<QDialog> d = new QDialog(this);
            Ui::HelpDialog hd;
            hd.setupUi(d);
            d->exec();
            delete d;
            break;
    }
}