From: Akos Polster Date: Sun, 5 Dec 2010 00:36:26 +0000 (+0100) Subject: Add new widget MainWindow. X-Git-Url: http://vcs.maemo.org/git/?p=dorian;a=commitdiff_plain;h=604e67a105161b6c303d00a6a55e04af14aebfd8 Add new widget MainWindow. --- diff --git a/adopterwindow.cpp b/adopterwindow.cpp index 29e8331..8d8e6d0 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -387,9 +387,3 @@ void AdopterWindow::onPageDown() } } -void AdopterWindow::hideToolBar() -{ - if (toolBar) { - toolBar->hide(); - } -} diff --git a/adopterwindow.h b/adopterwindow.h index c6c99cd..eca7669 100644 --- a/adopterwindow.h +++ b/adopterwindow.h @@ -1,8 +1,8 @@ #ifndef ADOPTERWINDOW_H #define ADOPTERWINDOW_H -#include #include +#include "mainwindow.h" class QWidget; class QToolBar; @@ -16,7 +16,7 @@ class TranslucentButton; * A toplevel window that can adopt a BookView and other children. * On Maemo, it can also grab the volume keys. */ -class AdopterWindow: public QMainWindow +class AdopterWindow: public MainWindow { Q_OBJECT diff --git a/dorian.pro b/dorian.pro index dbc4311..48ef01f 100644 --- a/dorian.pro +++ b/dorian.pro @@ -39,7 +39,8 @@ SOURCES += \ searchresultsdialog.cpp \ searchresultinfodialog.cpp \ widgets/progressdialog.cpp \ - widgets/splash.cpp + widgets/splash.cpp \ + widgets/mainwindow.cpp HEADERS += \ mainwindow.h \ @@ -80,7 +81,8 @@ HEADERS += \ searchresultsdialog.h \ searchresultinfodialog.h \ widgets/progressdialog.h \ - widgets/splash.h + widgets/splash.h \ + widgets/mainwindow.h RESOURCES += \ dorian.qrc diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp new file mode 100755 index 0000000..f3d176d --- /dev/null +++ b/widgets/mainwindow.cpp @@ -0,0 +1,146 @@ +#include + +#include "mainwindow.h" +#include "trace.h" +#include "platform.h" + +MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), toolBar(0) +{ + TRACE; + +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow, true); +#endif + + QFrame *frame = new QFrame(this); + QVBoxLayout *layout = new QVBoxLayout(frame); + layout->setMargin(0); + frame->setLayout(layout); + //frame->show(); + setCentralWidget(frame); + +#ifdef Q_OS_SYMBIAN + QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this); + closeAction->setSoftKeyRole(QAction::NegativeSoftKey); + connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); + QMainWindow::addAction(closeAction); +#else + // Tool bar + setUnifiedTitleAndToolBarOnMac(true); + toolBar = addToolBar(""); + toolBar->setMovable(false); + toolBar->setFloatable(false); + toolBar->toggleViewAction()->setVisible(false); +#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5) + toolBar->setIconSize(QSize(42, 42)); +#endif +#endif // Q_OS_SYMBIAN +} + +QAction *MainWindow::addToolBarAction(QObject *receiver, + const char *member, + const QString &iconName, + const QString &text, + bool important) +{ + TRACE; + qDebug() << "icon" << iconName << "text" << text; + QAction *action; +#ifndef Q_OS_SYMBIAN + Q_UNUSED(important); + action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)), + text, receiver, member); +#else + if (!toolBar && important) { + // Create tool bar if needed + toolBar = new QToolBar("", this); + // toolBar->setFixedHeight(63); + toolBar->setStyleSheet("margin:0; border:0; padding:0"); + toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, + QSizePolicy::Maximum); + addToolBar(Qt::BottomToolBarArea, toolBar); + } + if (important) { + // Add tool bar action + 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); + } + // Add menu action, too + action = new QAction(text, this); + menuBar()->addAction(action); + connect(action, SIGNAL(triggered()), receiver, member); +#endif + + action->setText(""); + action->setToolTip(""); + + return action; +} + +void MainWindow::addToolBarSpace() +{ +#ifndef Q_OS_SYMBIAN + QFrame *frame = new QFrame(toolBar); + frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + toolBar->addWidget(frame); +#endif +} + +#ifdef Q_OS_SYMBIAN + +void MainWindow::updateToolBar() +{ + TRACE; + if (toolBar) { + QRect geometry = QApplication::desktop()->geometry(); + bool isPortrait = geometry.width() < geometry.height(); + bool isToolBarHidden = toolBar->isHidden(); + if (isPortrait && isToolBarHidden) { + qDebug() << "Show tool bar"; + toolBar->setVisible(true); + } else if (!isPortrait && !isToolBarHidden) { + qDebug() << "Hide tool bar"; + toolBar->setVisible(false); + } + } +} + +bool MainWindow::portrait() +{ + QRect geometry = QApplication::desktop()->geometry(); + return geometry.width() < geometry.height(); +} + +#endif // Q_OS_SYMBIAN + +void MainWindow::showEvent(QShowEvent *e) +{ + Trace t("MainWindow::showEvent"); + +#ifdef Q_OS_SYMBIAN + updateToolBar(); +#endif + QMainWindow::showEvent(e); +} + +void MainWindow::resizeEvent(QResizeEvent *event) +{ + Trace t("MainWindow::resizeEvent"); +#ifdef Q_OS_SYMBIAN + updateToolBar(); +#endif + QMainWindow::resizeEvent(event); +} + +void MainWindow::hideToolBar() +{ + if (toolBar) { + toolBar->hide(); + } +} diff --git a/widgets/mainwindow.h b/widgets/mainwindow.h new file mode 100755 index 0000000..62b1ba3 --- /dev/null +++ b/widgets/mainwindow.h @@ -0,0 +1,61 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class QToolBar; + +/** + * Main window with a toolbar. + */ +class MainWindow: public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + + /** + * Add action that is visible on the tool bar. + * @param receiver Object receiving "activated" signal. + * @param slot Slot receiving "activated" signal. + * @param iconName Base name of tool bar icon in resource file. + * @param text Tool bar item text. + * @param important On Symbian, only "important" actions are added to + * the tool bar. All actions are added to the Options + * menu though. + */ + QAction *addToolBarAction(QObject *receiver, const char *slot, + const QString &iconName, const QString &text, + bool important = false); + + /** Add spacing to tool bar. */ + void addToolBarSpace(); + +signals: + +public slots: + +protected: + /** Handle resize event: Manage tool bar visibility. */ + void resizeEvent(QResizeEvent *event); + + /** Handle show event: Manage tool bar visibility. */ + void showEvent(QShowEvent *event); + +#ifdef Q_OS_SYMBIAN + /** Update toolbar visibility. */ + void updateToolBar(); + + /** Return true in portrait mode. */ + bool portrait(); +#endif // Q_OS_SYMBIAN + + /** Hide tool bar if visible. */ + void hideToolBar(); + +private: + QToolBar *toolBar; /**< Tool bar. */ +}; + +#endif // MAINWINDOW_H