clean up initialization code
This commit is contained in:
parent
a031920cd0
commit
5fc481e1e4
|
@ -3,29 +3,32 @@
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QStackedLayout>
|
||||||
|
#include <QDebug>
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "components/flatbutton.h"
|
#include "components/flatbutton.h"
|
||||||
#include "components/iconbutton.h"
|
#include "components/iconbutton.h"
|
||||||
#include "components/appbar.h"
|
#include "components/appbar.h"
|
||||||
|
#include "examples/about.h"
|
||||||
|
#include "examples/flatbuttonexamples.h"
|
||||||
|
#include "examples/iconbuttonexamples.h"
|
||||||
|
#include "examples/appbarexamples.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent),
|
||||||
|
_layout(new QStackedLayout),
|
||||||
|
_flatButtonExamples(new FlatButtonExamples),
|
||||||
|
_iconButtonExamples(new IconButtonExamples),
|
||||||
|
_appBarExamples(new AppBarExamples),
|
||||||
|
_about(new About)
|
||||||
{
|
{
|
||||||
QMenu *components = new QMenu("Components");
|
_initWidget();
|
||||||
components->addAction("AppBar");
|
_initMenu();
|
||||||
|
|
||||||
QMenu *buttons = new QMenu("Buttons");
|
|
||||||
components->addMenu(buttons);
|
|
||||||
|
|
||||||
buttons->addAction("FlatButton");
|
|
||||||
buttons->addAction("IconButton");
|
|
||||||
|
|
||||||
components->addAction("Tabs");
|
|
||||||
|
|
||||||
menuBar()->addMenu(components);
|
|
||||||
|
|
||||||
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
|
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
QWidget *widget = new QWidget;
|
QWidget *widget = new QWidget;
|
||||||
widget->setLayout(layout);
|
widget->setLayout(layout);
|
||||||
|
@ -69,8 +72,52 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
button2->setIcon(icon);
|
button2->setIcon(icon);
|
||||||
|
|
||||||
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
|
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::showWidget(QAction *action)
|
||||||
|
{
|
||||||
|
QString text(action->text());
|
||||||
|
if ("AppBar" == text) {
|
||||||
|
_layout->setCurrentWidget(_about);
|
||||||
|
} else if ("FlatButton" == text) {
|
||||||
|
_layout->setCurrentWidget(_flatButtonExamples);
|
||||||
|
} else if ("IconButton" == text) {
|
||||||
|
_layout->setCurrentWidget(_about);
|
||||||
|
} else {
|
||||||
|
_layout->setCurrentWidget(_about);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::_initWidget()
|
||||||
|
{
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
widget->setLayout(_layout);
|
||||||
|
|
||||||
|
_layout->addWidget(_about);
|
||||||
|
_layout->addWidget(_flatButtonExamples);
|
||||||
|
|
||||||
|
setCentralWidget(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::_initMenu() const
|
||||||
|
{
|
||||||
|
QMenu *components = new QMenu("Components");
|
||||||
|
components->addAction("AppBar");
|
||||||
|
|
||||||
|
QMenu *buttons = new QMenu("Buttons");
|
||||||
|
components->addMenu(buttons);
|
||||||
|
|
||||||
|
buttons->addAction("FlatButton");
|
||||||
|
buttons->addAction("IconButton");
|
||||||
|
|
||||||
|
components->addAction("Tabs");
|
||||||
|
|
||||||
|
menuBar()->addMenu(components);
|
||||||
|
|
||||||
|
connect(components, SIGNAL(triggered(QAction *)), this, SLOT(showWidget(QAction *)));
|
||||||
|
}
|
||||||
|
|
19
mainwindow.h
19
mainwindow.h
|
@ -3,6 +3,12 @@
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
class About;
|
||||||
|
class FlatButtonExamples;
|
||||||
|
class IconButtonExamples;
|
||||||
|
class AppBarExamples;
|
||||||
|
class QStackedLayout;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -10,6 +16,19 @@ class MainWindow : public QMainWindow
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void showWidget(QAction *action);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _initWidget();
|
||||||
|
void _initMenu() const;
|
||||||
|
|
||||||
|
QStackedLayout *const _layout;
|
||||||
|
FlatButtonExamples *const _flatButtonExamples;
|
||||||
|
IconButtonExamples *const _iconButtonExamples;
|
||||||
|
AppBarExamples *const _appBarExamples;
|
||||||
|
About *const _about;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
Loading…
Reference in New Issue