diff --git a/src/main.cpp b/src/main.cpp index bde6abf..896dda9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ bool setupOptions(AnyOption *cmdopts) cmdopts->addUsage(" -c --config options.ini Configuration INI-file"); cmdopts->addUsage(" -u --uri http://www.example.com/ Open this URI, home page"); cmdopts->addUsage(" -C --clear-cache Clear cached request data"); + cmdopts->addUsage(" -R --rotate Rotate display 90 degrees"); cmdopts->addUsage(""); cmdopts->addUsage("Build with:"); cmdopts->addUsage(" Qt: " QT_VERSION_STR); @@ -71,6 +72,7 @@ bool setupOptions(AnyOption *cmdopts) cmdopts->setFlag("help", 'h'); cmdopts->setFlag("version", 'v'); cmdopts->setFlag("clear-cache", 'C'); + cmdopts->setFlag("rotate", 'R'); cmdopts->setOption("config", 'c'); cmdopts->setOption("uri", 'u'); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ac9cd4d..2cf9817 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -168,7 +168,7 @@ void MainWindow::init(AnyOption *opts) } // --- Web View --- // - view = new WebView(this); + view = new WebView(); QPalette paletteG = this->palette(); paletteG.setColor(QPalette::Window, QColor(220,240,220,127)); @@ -215,8 +215,6 @@ void MainWindow::init(AnyOption *opts) topBox->addWidget(messagesBox, 1, Qt::AlignTop | Qt::AlignLeft); } - setCentralWidget(view); - view->setSettings(qwkSettings); view->setPage(new QwkWebPage(view)); @@ -245,6 +243,7 @@ void MainWindow::init(AnyOption *opts) nm->setCache(diskCache); view->page()->setNetworkAccessManager(nm); } + rotated = cmdopts->getFlag("rotate"); if (qwkSettings->getBool("browser/cookiejar")) { view->page()->networkAccessManager()->setCookieJar(new PersistentCookieJar()); @@ -345,8 +344,21 @@ void MainWindow::init(AnyOption *opts) } delayedLoad->singleShot(delay_load, this, SLOT(delayedPageLoad())); + graphicsView = new QGraphicsView(this); + graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + graphicsScene = new QGraphicsScene(graphicsView); + proxyWidget = graphicsScene->addWidget(view); + graphicsView->fitInView(proxyWidget); + if (rotated) + proxyWidget->setRotation(90); + graphicsView->setScene(graphicsScene); + graphicsView->setVisible(true); + proxyWidget->setVisible(true); + setCentralWidget(graphicsView); } + void MainWindow::delayedWindowResize() { qDebug("Setting focus policy, window size"); @@ -370,7 +382,13 @@ void MainWindow::delayedWindowResize() void MainWindow::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); - // Your code here. + if (graphicsView && view) { + auto size = event->size(); + if (rotated) + view->resize(size.height(), size.width()); + else + view->resize(size); + } } void MainWindow::delayedPageLoad() diff --git a/src/mainwindow.h b/src/mainwindow.h index 01ccbb8..36a946f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -48,6 +48,9 @@ #include #include #include +#include +#include +#include #ifdef USE_TESTLIB #include @@ -118,6 +121,8 @@ protected slots: void resizeEvent(QResizeEvent* event); private: + bool rotated; // Are we rotating 90 degrees? + WebView *view; // Webkit Page View QHBoxLayout *topBox; // Box for progress and messages QProgressBar *loadProgress; // progress bar to display page loading @@ -133,6 +138,10 @@ protected slots: AnyOption *cmdopts; UnixSignals *handler; + QGraphicsView *graphicsView; + QGraphicsScene *graphicsScene; + QGraphicsProxyWidget *proxyWidget; + #ifdef USE_TESTLIB QTestEventList *simulateClick; #endif