From b4a54bf32438a3eee18975e46632bd9e3e653518 Mon Sep 17 00:00:00 2001 From: haruyukilxz Date: Mon, 12 Mar 2018 16:10:59 +0800 Subject: [PATCH] feat: add navigation button Change-Id: Ib1a588eb5153fa7e9899797177301a819b28a82c --- src/main.cc | 4 -- src/mainwindow.cc | 18 ++++- src/mainwindow.h | 52 +++++++-------- src/modules/desktopmodemodule.cc | 11 +++ src/modules/desktopmodemodule.h | 4 +- src/modules/iconmodule.cc | 11 +++ src/modules/iconmodule.h | 3 + src/modules/normalmodule.cc | 111 +++++++++++++++++++++++++++++++ src/modules/normalmodule.h | 42 ++++++++++++ src/modules/wmmodemodule.cc | 11 +++ src/modules/wmmodemodule.h | 3 + src/widgets/basewidget.cc | 2 + src/widgets/navigationbutton.cc | 41 ++++++++++++ src/widgets/navigationbutton.h | 34 ++++++++++ 14 files changed, 314 insertions(+), 33 deletions(-) create mode 100644 src/modules/normalmodule.cc create mode 100644 src/modules/normalmodule.h create mode 100644 src/widgets/navigationbutton.cc create mode 100644 src/widgets/navigationbutton.h diff --git a/src/main.cc b/src/main.cc index 708f417..1977971 100644 --- a/src/main.cc +++ b/src/main.cc @@ -42,9 +42,5 @@ int main(int argc, char *argv[]) w.moveToCenter(); w.exec(); - NormalWindow n; - n.setFixedWidth(750); - n.exec(); - return 0; } diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 6b3375c..7bc4a79 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -21,6 +21,7 @@ #include "modules/desktopmodemodule.h" #include "modules/wmmodemodule.h" #include "modules/iconmodule.h" +#include "modules/normalmodule.h" #include "basemodulewidget.h" #include @@ -146,13 +147,17 @@ void MainWindow::updateModule(const int index) m_current = initIconModule(); break; case 5: - close(); + m_current = initNormalModule(); + m_nextBtn->hide(); + m_previousBtn->hide(); + setFixedSize(900, 450); + m_fakerWidget->setFixedSize(900, 450); + m_current->setFixedSize(900, 450); break; default: break; } - m_current->setFixedSize(WINDOW_SIZE); m_current->show(); bindAnimation(); @@ -169,6 +174,7 @@ void MainWindow::animationHandle() BaseModuleWidget *MainWindow::initVideoWidgt() { BaseModuleWidget* w = new BaseModuleWidget(new VideoWidget, m_fakerWidget); + w->setFixedSize(WINDOW_SIZE); return w; } @@ -180,6 +186,7 @@ BaseModuleWidget *MainWindow::initDesktopModeModule() BaseModuleWidget* w = new BaseModuleWidget(module, m_fakerWidget); w->setTitle(tr("Please select desktop mode")); w->setDescribe(tr("You can switch it in Mode by right clicking on dock")); + w->setFixedSize(WINDOW_SIZE); return w; } @@ -189,6 +196,7 @@ BaseModuleWidget *MainWindow::initWMModeModule() module->updateBigIcon(); BaseModuleWidget* w = new BaseModuleWidget(module, m_fakerWidget); + w->setFixedSize(WINDOW_SIZE); return w; } @@ -200,5 +208,11 @@ BaseModuleWidget *MainWindow::initIconModule() BaseModuleWidget* w = new BaseModuleWidget(module, m_fakerWidget); w->setTitle(tr("Please select icon theme")); w->setDescribe(tr("You can change it in Control Center > Personalization > Theme > Icon Theme")); + w->setFixedSize(WINDOW_SIZE); return w; } + +BaseModuleWidget *MainWindow::initNormalModule() +{ + return new BaseModuleWidget(new NormalModule, m_fakerWidget); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 5d23c1b..4ef9cfe 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -19,47 +19,47 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include #include +#include #include -#include DWIDGET_USE_NAMESPACE class BaseModuleWidget; -class MainWindow : public DDialog -{ - Q_OBJECT +class MainWindow : public DDialog { + Q_OBJECT public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); + MainWindow(QWidget *parent = 0); + ~MainWindow(); private Q_SLOTS: - void previous(); - void next(); + void previous(); + void next(); private: - void initUI(); - void initConnect(); - void bindAnimation(); - void updateModule(const int index); - void animationHandle(); + void initUI(); + void initConnect(); + void bindAnimation(); + void updateModule(const int index); + void animationHandle(); - BaseModuleWidget* initVideoWidgt(); - BaseModuleWidget* initDesktopModeModule(); - BaseModuleWidget* initWMModeModule(); - BaseModuleWidget* initIconModule(); + BaseModuleWidget *initVideoWidgt(); + BaseModuleWidget *initDesktopModeModule(); + BaseModuleWidget *initWMModeModule(); + BaseModuleWidget *initIconModule(); + BaseModuleWidget *initNormalModule(); private: - int m_index; - QPushButton* m_nextBtn; - DImageButton* m_previousBtn; - QWidget *m_current; - QWidget *m_last; - QPropertyAnimation *m_currentAni; - QPropertyAnimation *m_lastAni; - QWidget* m_fakerWidget; + int m_index; + QPushButton *m_nextBtn; + DImageButton *m_previousBtn; + QWidget *m_current; + QWidget *m_last; + QPropertyAnimation *m_currentAni; + QPropertyAnimation *m_lastAni; + QWidget *m_fakerWidget; }; #endif // MAINWINDOW_H diff --git a/src/modules/desktopmodemodule.cc b/src/modules/desktopmodemodule.cc index 63156a6..73a4c43 100644 --- a/src/modules/desktopmodemodule.cc +++ b/src/modules/desktopmodemodule.cc @@ -45,6 +45,8 @@ DesktopModeModule::DesktopModeModule(QWidget *parent) m_layout->addWidget(m_fashionWidget); setLayout(m_layout); + + updateSmaillIcon(); } void DesktopModeModule::onDesktopTypeChanged(Model::DesktopMode mode) @@ -75,4 +77,13 @@ void DesktopModeModule::updateSmaillIcon() m_fashionWidget->setPixmap(":/resources/fashion_mode_small.png"); } +void DesktopModeModule::resizeEvent(QResizeEvent *event) +{ + ModuleInterface::resizeEvent(event); + + QTimer::singleShot(1, this, [=] { + onDesktopTypeChanged(m_model->desktopMode()); + }); +} + diff --git a/src/modules/desktopmodemodule.h b/src/modules/desktopmodemodule.h index 7c837cf..00c8831 100644 --- a/src/modules/desktopmodemodule.h +++ b/src/modules/desktopmodemodule.h @@ -36,10 +36,12 @@ class DesktopModeModule : public ModuleInterface void updateBigIcon() Q_DECL_OVERRIDE; void updateSmaillIcon() Q_DECL_OVERRIDE; +protected: + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + private Q_SLOTS: void onDesktopTypeChanged(Model::DesktopMode mode); - private: QHBoxLayout* m_layout; BaseWidget* m_efficientWidget; diff --git a/src/modules/iconmodule.cc b/src/modules/iconmodule.cc index 6592dc0..af43826 100644 --- a/src/modules/iconmodule.cc +++ b/src/modules/iconmodule.cc @@ -40,6 +40,8 @@ IconModule::IconModule(QWidget *parent) m_layout->setContentsMargins(15, 8, 10, 0); setLayout(m_layout); + + updateSmaillIcon(); } void IconModule::addIcon(const IconStruct &icon) @@ -96,3 +98,12 @@ void IconModule::updateSmaillIcon() { } + +void IconModule::resizeEvent(QResizeEvent *event) +{ + ModuleInterface::resizeEvent(event); + + QTimer::singleShot(1, this, [=] { + currentIconChanged(m_model->currentIcon()); + }); +} diff --git a/src/modules/iconmodule.h b/src/modules/iconmodule.h index a008800..895b91d 100644 --- a/src/modules/iconmodule.h +++ b/src/modules/iconmodule.h @@ -39,6 +39,9 @@ class IconModule : public ModuleInterface void updateBigIcon() Q_DECL_OVERRIDE; void updateSmaillIcon() Q_DECL_OVERRIDE; +protected: + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + private Q_SLOTS: void addIcon(const IconStruct &icon); void removeIcon(const IconStruct &icon); diff --git a/src/modules/normalmodule.cc b/src/modules/normalmodule.cc new file mode 100644 index 0000000..0e84d93 --- /dev/null +++ b/src/modules/normalmodule.cc @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: kirigaya + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "normalmodule.h" +#include "../widgets/navigationbutton.h" +#include "desktopmodemodule.h" +#include "iconmodule.h" +#include "wmmodemodule.h" +#include "videowidget.h" + +NormalModule::NormalModule(QWidget *parent) + : QWidget(parent) + , m_leftNavigationLayout(new QVBoxLayout) + , m_rightContentLayout(new QVBoxLayout) + , m_buttonGrp(new QButtonGroup) + , m_currentWidget(nullptr) +{ + QWidget *content = new QWidget; + content->setLayout(m_rightContentLayout); + + QHBoxLayout *layout = new QHBoxLayout(this); + + m_leftNavigationLayout->setMargin(0); + + m_rightContentLayout->setSpacing(0); + m_rightContentLayout->setMargin(0); + + layout->setMargin(0); + layout->setSpacing(0); + + layout->addLayout(m_leftNavigationLayout); + layout->addWidget(content); + + setLayout(layout); + + setMinimumSize(900, 450); + content->setFixedSize(700, 450); + + NavigationButton * videoBtn = new NavigationButton; + NavigationButton * desktopBtn = new NavigationButton; + NavigationButton * iconBtn = new NavigationButton; + NavigationButton * wmBtn = new NavigationButton; + + VideoWidget *video = new VideoWidget; + DesktopModeModule *desktop = new DesktopModeModule; + IconModule *icon = new IconModule; + WMModeModule *wm = new WMModeModule; + + m_rightContentLayout->addWidget(video); + m_rightContentLayout->addWidget(desktop); + m_rightContentLayout->addWidget(icon); + m_rightContentLayout->addWidget(wm); + + video->setFixedSize(700, height()); + desktop->setFixedSize(700, height()); + icon->setFixedSize(700, height()); + wm->setFixedSize(700, height()); + + video->hide(); + desktop->hide(); + icon->hide(); + wm->hide(); + + m_moduleMap[videoBtn] = video; + m_moduleMap[desktopBtn] = desktop; + m_moduleMap[iconBtn] = icon; + m_moduleMap[wmBtn] = wm; + + m_currentWidget = video; + + videoBtn->setFixedWidth(200); + desktopBtn->setFixedWidth(200); + iconBtn->setFixedWidth(200); + wmBtn->setFixedWidth(200); + + m_buttonGrp->addButton(videoBtn); + m_buttonGrp->addButton(desktopBtn); + m_buttonGrp->addButton(iconBtn); + m_buttonGrp->addButton(wmBtn); + + m_buttonGrp->setExclusive(true); + + m_leftNavigationLayout->addStretch(); + m_leftNavigationLayout->addWidget(videoBtn, 0, Qt::AlignLeft | Qt::AlignVCenter); + m_leftNavigationLayout->addWidget(desktopBtn, 0, Qt::AlignLeft | Qt::AlignVCenter); + m_leftNavigationLayout->addWidget(iconBtn, 0, Qt::AlignLeft | Qt::AlignVCenter); + m_leftNavigationLayout->addWidget(wmBtn, 0, Qt::AlignLeft | Qt::AlignVCenter); + m_leftNavigationLayout->addStretch(); + + connect(m_buttonGrp, static_cast(&QButtonGroup::buttonClicked), this, [=] (QAbstractButton *btn) { + QWidget *w = m_moduleMap[btn]; + m_currentWidget->hide(); + w->show(); + m_currentWidget = w; + }); +} diff --git a/src/modules/normalmodule.h b/src/modules/normalmodule.h new file mode 100644 index 0000000..c97be71 --- /dev/null +++ b/src/modules/normalmodule.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: kirigaya + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NORMALMODULE_H +#define NORMALMODULE_H + +#include +#include +#include +#include +#include + +class NormalModule : public QWidget +{ + Q_OBJECT +public: + explicit NormalModule(QWidget *parent = nullptr); + +private: + QVBoxLayout *m_leftNavigationLayout; + QVBoxLayout *m_rightContentLayout; + QButtonGroup *m_buttonGrp; + QMap m_moduleMap; + QWidget *m_currentWidget; +}; + +#endif // NORMALMODULE_H diff --git a/src/modules/wmmodemodule.cc b/src/modules/wmmodemodule.cc index f9f31da..87899e7 100644 --- a/src/modules/wmmodemodule.cc +++ b/src/modules/wmmodemodule.cc @@ -45,6 +45,8 @@ WMModeModule::WMModeModule(QWidget *parent) m_layout->addWidget(m_fashionWidget); setLayout(m_layout); + + updateSmaillIcon(); } void WMModeModule::updateBigIcon() @@ -59,6 +61,15 @@ void WMModeModule::updateSmaillIcon() m_fashionWidget->setPixmap(":/resources/3d_small.png"); } +void WMModeModule::resizeEvent(QResizeEvent *event) +{ + ModuleInterface::resizeEvent(event); + + QTimer::singleShot(1, this, [=] { + onWMModeChanged(m_model->wmType()); + }); +} + void WMModeModule::onWMModeChanged(Model::WMType type) { m_selectBtn->raise(); diff --git a/src/modules/wmmodemodule.h b/src/modules/wmmodemodule.h index 145ca98..179527f 100644 --- a/src/modules/wmmodemodule.h +++ b/src/modules/wmmodemodule.h @@ -36,6 +36,9 @@ class WMModeModule : public ModuleInterface void updateBigIcon() Q_DECL_OVERRIDE; void updateSmaillIcon() Q_DECL_OVERRIDE; +protected: + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + private Q_SLOTS: void onWMModeChanged(Model::WMType type); diff --git a/src/widgets/basewidget.cc b/src/widgets/basewidget.cc index 8bb91ec..1f29120 100644 --- a/src/widgets/basewidget.cc +++ b/src/widgets/basewidget.cc @@ -31,9 +31,11 @@ BaseWidget::BaseWidget(QWidget *parent) m_layout->setMargin(0); m_layout->setSpacing(0); + m_layout->addStretch(); m_layout->addWidget(m_borderWidget, 0, Qt::AlignCenter); m_layout->addSpacing(5); m_layout->addWidget(m_title, 0, Qt::AlignCenter); + m_layout->addStretch(); setLayout(m_layout); } diff --git a/src/widgets/navigationbutton.cc b/src/widgets/navigationbutton.cc new file mode 100644 index 0000000..eadff20 --- /dev/null +++ b/src/widgets/navigationbutton.cc @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: kirigaya + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "navigationbutton.h" + +#include + +NavigationButton::NavigationButton(QWidget *parent) + : QPushButton(parent) +{ +} + +void NavigationButton::paintEvent(QPaintEvent *event) +{ + QPushButton::paintEvent(event); + + if (!isChecked()) + return; + + // right border + QRect r = rect(); + r.setLeft(r.right() - 2); + + QPainter painter(this); + painter.fillRect(r, QColor(44, 167, 248)); +} diff --git a/src/widgets/navigationbutton.h b/src/widgets/navigationbutton.h new file mode 100644 index 0000000..5e2b00d --- /dev/null +++ b/src/widgets/navigationbutton.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: kirigaya + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NAVIGATIONBUTTON_H +#define NAVIGATIONBUTTON_H + +#include + +class NavigationButton : public QPushButton +{ + Q_OBJECT +public: + explicit NavigationButton(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event); +}; + +#endif // NAVIGATIONBUTTON_H