From b54601372532fc7120518051b7a54b0a0d24803e Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Sun, 5 Dec 2010 01:37:37 +0100 Subject: [PATCH] Rename widgets/mainwindow to widgets/mainbase. --- dorian.pro | 4 +- widgets/mainbase.cpp | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ widgets/mainbase.h | 61 ++++++++++++++++++++ widgets/mainwindow.cpp | 146 ------------------------------------------------ widgets/mainwindow.h | 61 -------------------- 5 files changed, 209 insertions(+), 209 deletions(-) create mode 100755 widgets/mainbase.cpp create mode 100755 widgets/mainbase.h delete mode 100755 widgets/mainwindow.cpp delete mode 100755 widgets/mainwindow.h diff --git a/dorian.pro b/dorian.pro index 48ef01f..6911270 100644 --- a/dorian.pro +++ b/dorian.pro @@ -40,7 +40,7 @@ SOURCES += \ searchresultinfodialog.cpp \ widgets/progressdialog.cpp \ widgets/splash.cpp \ - widgets/mainwindow.cpp + widgets/mainbase.cpp HEADERS += \ mainwindow.h \ @@ -82,7 +82,7 @@ HEADERS += \ searchresultinfodialog.h \ widgets/progressdialog.h \ widgets/splash.h \ - widgets/mainwindow.h + widgets/mainbase.h RESOURCES += \ dorian.qrc diff --git a/widgets/mainbase.cpp b/widgets/mainbase.cpp new file mode 100755 index 0000000..f3d176d --- /dev/null +++ b/widgets/mainbase.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/mainbase.h b/widgets/mainbase.h new file mode 100755 index 0000000..62b1ba3 --- /dev/null +++ b/widgets/mainbase.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 diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp deleted file mode 100755 index f3d176d..0000000 --- a/widgets/mainwindow.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#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 deleted file mode 100755 index 62b1ba3..0000000 --- a/widgets/mainwindow.h +++ /dev/null @@ -1,61 +0,0 @@ -#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 -- 1.7.9.5