From: Akos Polster Date: Mon, 22 Nov 2010 21:16:28 +0000 (+0100) Subject: Add tool bar on Symbian. Fix some orientation change bugs. X-Git-Url: http://vcs.maemo.org/git/?p=dorian;a=commitdiff_plain;h=549e8d8b51f631005863aa7f4f3cb2683a901669 Add tool bar on Symbian. Fix some orientation change bugs. --- diff --git a/adopterwindow.cpp b/adopterwindow.cpp index 2c4bf8f..a819594 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -14,7 +14,7 @@ #include "settings.h" AdopterWindow::AdopterWindow(QWidget *parent): - QMainWindow(parent), bookView(0), grabbingVolumeKeys(false) + QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0) { TRACE; @@ -26,6 +26,7 @@ AdopterWindow::AdopterWindow(QWidget *parent): QVBoxLayout *layout = new QVBoxLayout(frame); layout->setMargin(0); frame->setLayout(layout); + frame->show(); setCentralWidget(frame); #ifdef Q_OS_SYMBIAN @@ -33,15 +34,6 @@ AdopterWindow::AdopterWindow(QWidget *parent): closeAction->setSoftKeyRole(QAction::NegativeSoftKey); connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); QMainWindow::addAction(closeAction); - - // toolBar = new QToolBar(this); - // toolBar->setFixedWidth(QApplication::desktop()-> - // availableGeometry().width()); - // toolBar->setFixedHeight(70); - // toolBar->setIconSize(QSize(90, 70)); - // toolBar->setFloatable(false); - // toolBar->setMovable(false); - // addToolBar(Qt::BottomToolBarArea, toolBar); #else // Tool bar setUnifiedTitleAndToolBarOnMac(true); @@ -67,7 +59,9 @@ void AdopterWindow::takeChildren(BookView *view, const QList &others) bookView = view; bookView->setParent(centralWidget()); bookView->show(); - centralWidget()->layout()->addWidget(bookView); + QVBoxLayout *layout = + qobject_cast(centralWidget()->layout()); + layout->addWidget(bookView, 1); } foreach (QWidget *child, others) { if (child) { @@ -120,14 +114,15 @@ QAction *AdopterWindow::addToolBarAction(QObject *receiver, action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)), text, receiver, member); #else - if (0) { // if (important) { - qDebug() << "Add Symbian tool bar action"; - QAction *toolBarAction = toolBar->addAction( - QIcon(Platform::instance()->icon(iconName)), - text, receiver, member); - toolBarAction->setText(""); - toolBarAction->setToolTip(""); - connect(toolBarAction, SIGNAL(triggered()), receiver, member); + if (toolBar && important) { + QPushButton *button = new QPushButton(this); + button->setIconSize(QSize(60, 60)); + button->setFixedSize(89, 60); + button->setIcon(QIcon(Platform::instance()->icon(iconName))); + button->setSizePolicy(QSizePolicy::MinimumExpanding, + QSizePolicy::Maximum); + connect(button, SIGNAL(clicked()), receiver, member); + toolBar->addWidget(button); } action = new QAction(text, this); menuBar()->addAction(action); diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp index 46742c7..ca8baba 100644 --- a/fullscreenwindow.cpp +++ b/fullscreenwindow.cpp @@ -2,11 +2,15 @@ #include "fullscreenwindow.h" #include "translucentbutton.h" +#include "progress.h" #include "trace.h" #include "settings.h" #include "platform.h" -FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent) +static const int MARGIN = 9; + +FullScreenWindow::FullScreenWindow(QWidget *parent): + AdopterWindow(parent), progress(0), previousButton(0), nextButton(0) { TRACE; Q_ASSERT(parent); @@ -24,9 +28,11 @@ FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent) setCentralWidget(frame); restoreButton = new TranslucentButton("view-normal", this); QRect screen = QApplication::desktop()->screenGeometry(); - restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9, - screen.height() - TranslucentButton::pixels - 9, - TranslucentButton::pixels, TranslucentButton::pixels); + restoreButton->setGeometry( + screen.width() - TranslucentButton::pixels - MARGIN, + screen.height() - TranslucentButton::pixels - MARGIN, + TranslucentButton::pixels, + TranslucentButton::pixels); connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore())); } @@ -57,9 +63,45 @@ void FullScreenWindow::resizeEvent(QResizeEvent *e) } #endif // Q_WS_MAEMO_5 - restoreButton->setGeometry(w - TranslucentButton::pixels - 9, - h - TranslucentButton::pixels - 9, TranslucentButton::pixels, + restoreButton->setGeometry( + w - TranslucentButton::pixels - MARGIN, + h - TranslucentButton::pixels - MARGIN, + TranslucentButton::pixels, + TranslucentButton::pixels); + + if (hasChild(progress)) { + progress->setGeometry(0, h - progress->thickness(), + w, progress->thickness()); + } + if (hasChild(previousButton)) { + previousButton->setGeometry( + MARGIN, + h - TranslucentButton::pixels - MARGIN, + TranslucentButton::pixels, + TranslucentButton::pixels); + } + if (hasChild(nextButton)) { + nextButton->setGeometry( + w - TranslucentButton::pixels - MARGIN, + MARGIN, + TranslucentButton::pixels, TranslucentButton::pixels); + } + restoreButton->flash(3000); AdopterWindow::resizeEvent(e); } + +void FullScreenWindow::takeChildren(BookView *view, + Progress *prog, + TranslucentButton *previous, + TranslucentButton *next) +{ + TRACE; + progress = prog; + previousButton = previous; + nextButton = next; + QList otherChildren; + otherChildren << progress << previousButton << nextButton; + AdopterWindow::takeChildren(view, otherChildren); +} diff --git a/fullscreenwindow.h b/fullscreenwindow.h index 601269b..c30c309 100644 --- a/fullscreenwindow.h +++ b/fullscreenwindow.h @@ -10,6 +10,7 @@ class QWidget; class QMouseEvent; class QResizeEvent; class TranslucentButton; +class Progress; /** A full screen window with a restore button. */ class FullScreenWindow: public AdopterWindow @@ -18,17 +19,31 @@ class FullScreenWindow: public AdopterWindow public: explicit FullScreenWindow(QWidget *parent); + + /** Swith to full screen, and flash the restore button. */ void showFullScreen(); + /** + * Adopt children. + * Same as @AdopterWindow::takeChildren(), but saves prog, previous + * and next, before calling base class method. + */ + void takeChildren(BookView *bookView, Progress *prog, + TranslucentButton *previous, TranslucentButton *next); + signals: /** Emitted when the restore button is pressed. */ void restore(); protected: + /** Handle size (and orientation) change. */ void resizeEvent(QResizeEvent *e); private: TranslucentButton *restoreButton; + Progress *progress; + TranslucentButton *previousButton; + TranslucentButton *nextButton; }; #endif // FULLSCREENWINDOW_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 4172e68..8f6e2ef 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -44,6 +44,17 @@ MainWindow::MainWindow(QWidget *parent): #endif setWindowTitle("Dorian"); +#ifdef Q_OS_SYMBIAN + // Tool bar + toolBar = new QToolBar("", this /*frame*/); + toolBar->setFixedWidth(QApplication::desktop()-> + availableGeometry().width()); + toolBar->setFixedHeight(65); + toolBar->setStyleSheet("margin:0;border:0;padding:0"); + toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); + addToolBar(Qt::BottomToolBarArea, toolBar); +#endif + // Central widget. Must be an intermediate, because the book view widget // can be re-parented later QFrame *central = new QFrame(this); @@ -194,22 +205,28 @@ void MainWindow::showRegular() QRect geo = geometry(); qDebug() << geo; int y = geo.height() - progress->thickness(); -#if defined(Q_WS_MAEMO_5) - y -= toolBar->height(); +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) + bool hasToolBar = false; +# if defined(Q_OS_SYMBIAN) + hasToolBar = + (QApplication::desktop()->width() < QApplication::desktop()->height()); + qDebug() << (hasToolBar? "Portrait": "Landscape"); +# endif + if (!hasToolBar) { + y -= toolBar->height(); + } #endif progress->setGeometry(0, y, geo.width(), y + progress->thickness()); -#if defined(Q_WS_MAEMO_5) - previousButton->setGeometry(0, - geo.height() - toolBar->height() - TranslucentButton::pixels, - TranslucentButton::pixels, TranslucentButton::pixels); +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) + y = geo.height() - TranslucentButton::pixels; + if (!hasToolBar) { + y -= toolBar->height(); + } + previousButton->setGeometry(0, y, TranslucentButton::pixels, + TranslucentButton::pixels); nextButton->setGeometry(geo.width() - TranslucentButton::pixels, 0, TranslucentButton::pixels, TranslucentButton::pixels); -#elif defined(Q_OS_SYMBIAN) - previousButton->setGeometry(0, geo.height() - TranslucentButton::pixels, - TranslucentButton::pixels, TranslucentButton::pixels); - nextButton->setGeometry(geo.width() - TranslucentButton::pixels, - 0, TranslucentButton::pixels, TranslucentButton::pixels); #else previousButton->setGeometry(0, geo.height() - TranslucentButton::pixels, TranslucentButton::pixels, TranslucentButton::pixels); @@ -235,9 +252,7 @@ void MainWindow::showBig() // Re-parent children leaveChildren(); - QList otherChildren; - otherChildren << progress << nextButton << previousButton; - fullScreenWindow->takeChildren(view, otherChildren); + fullScreenWindow->takeChildren(view, progress, previousButton, nextButton); // Adjust geometry of decorations QRect screen = QApplication::desktop()->screenGeometry(); @@ -429,14 +444,25 @@ void MainWindow::resizeEvent(QResizeEvent *e) { TRACE; + int toolBarHeight = 0; + +#ifdef Q_OS_SYMBIAN + // Tool bar is only useful in portrait mode + bool isPortrait = (e->size().width() < e->size().height()); + toolBar->setVisible(isPortrait); + if (!isPortrait) { + toolBarHeight = toolBar->height(); + } +#endif // Q_OS_SYMBIAN + if (bookView) { qDebug() << "BookView geometry" << bookView->geometry(); QRect geo = bookView->geometry(); progress->setGeometry(geo.x(), - geo.y() + geo.height() - progress->thickness(), geo.width(), - progress->thickness()); + geo.y() + geo.height() - progress->thickness() + toolBarHeight, + geo.width(), progress->thickness()); previousButton->setGeometry(geo.x(), - geo.y() + geo.height() - TranslucentButton::pixels, + geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight, TranslucentButton::pixels, TranslucentButton::pixels); nextButton->setGeometry( geo.x() + geo.width() - TranslucentButton::pixels, diff --git a/pkg/changelog b/pkg/changelog index be7090c..d4bb2f4 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -1,5 +1,7 @@ dorian (0.4.0-1) unstable; urgency=low + * Fix popup button positions + -- Akos Polster Sun, 21 Nov 2010 02:00:00 +0100 dorian (0.3.9-1) unstable; urgency=low