Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --rotate command line flag to rotate the view #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
26 changes: 22 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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");
Expand All @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include <QMainWindow>
#include <QtNetwork>
#include <QtWebKit>
#include <QtWebKitWidgets/QWebFrame>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>

#ifdef USE_TESTLIB
#include <QtTest/QTestEventList>
Expand Down Expand Up @@ -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
Expand All @@ -133,6 +138,10 @@ protected slots:
AnyOption *cmdopts;
UnixSignals *handler;

QGraphicsView *graphicsView;
QGraphicsScene *graphicsScene;
QGraphicsProxyWidget *proxyWidget;

#ifdef USE_TESTLIB
QTestEventList *simulateClick;
#endif
Expand Down