Skip to content

Commit

Permalink
feat: add navigation button
Browse files Browse the repository at this point in the history
Change-Id: Ib1a588eb5153fa7e9899797177301a819b28a82c
  • Loading branch information
justforlxz committed Mar 15, 2018
1 parent 8e4628c commit b4a54bf
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 33 deletions.
4 changes: 0 additions & 4 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,5 @@ int main(int argc, char *argv[])
w.moveToCenter();
w.exec();

NormalWindow n;
n.setFixedWidth(750);
n.exec();

return 0;
}
18 changes: 16 additions & 2 deletions src/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "modules/desktopmodemodule.h"
#include "modules/wmmodemodule.h"
#include "modules/iconmodule.h"
#include "modules/normalmodule.h"
#include "basemodulewidget.h"

#include <QHBoxLayout>
Expand Down Expand Up @@ -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();
Expand All @@ -169,6 +174,7 @@ void MainWindow::animationHandle()
BaseModuleWidget *MainWindow::initVideoWidgt()
{
BaseModuleWidget* w = new BaseModuleWidget(new VideoWidget, m_fakerWidget);
w->setFixedSize(WINDOW_SIZE);
return w;
}

Expand All @@ -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;
}

Expand All @@ -189,6 +196,7 @@ BaseModuleWidget *MainWindow::initWMModeModule()
module->updateBigIcon();

BaseModuleWidget* w = new BaseModuleWidget(module, m_fakerWidget);
w->setFixedSize(WINDOW_SIZE);
return w;
}

Expand All @@ -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);
}
52 changes: 26 additions & 26 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,47 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <ddialog.h>
#include <QPropertyAnimation>
#include <QPushButton>
#include <ddialog.h>
#include <dimagebutton.h>
#include <QPropertyAnimation>

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
11 changes: 11 additions & 0 deletions src/modules/desktopmodemodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ DesktopModeModule::DesktopModeModule(QWidget *parent)
m_layout->addWidget(m_fashionWidget);

setLayout(m_layout);

updateSmaillIcon();
}

void DesktopModeModule::onDesktopTypeChanged(Model::DesktopMode mode)
Expand Down Expand Up @@ -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());
});
}


4 changes: 3 additions & 1 deletion src/modules/desktopmodemodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/modules/iconmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -96,3 +98,12 @@ void IconModule::updateSmaillIcon()
{

}

void IconModule::resizeEvent(QResizeEvent *event)
{
ModuleInterface::resizeEvent(event);

QTimer::singleShot(1, this, [=] {
currentIconChanged(m_model->currentIcon());
});
}
3 changes: 3 additions & 0 deletions src/modules/iconmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
111 changes: 111 additions & 0 deletions src/modules/normalmodule.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: kirigaya <kirigaya@mkacg.com>
* 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 <http://www.gnu.org/licenses/>.
*/

#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<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked), this, [=] (QAbstractButton *btn) {
QWidget *w = m_moduleMap[btn];
m_currentWidget->hide();
w->show();
m_currentWidget = w;
});
}
42 changes: 42 additions & 0 deletions src/modules/normalmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: kirigaya <kirigaya@mkacg.com>
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef NORMALMODULE_H
#define NORMALMODULE_H

#include <QWidget>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QPushButton>
#include <QMap>

class NormalModule : public QWidget
{
Q_OBJECT
public:
explicit NormalModule(QWidget *parent = nullptr);

private:
QVBoxLayout *m_leftNavigationLayout;
QVBoxLayout *m_rightContentLayout;
QButtonGroup *m_buttonGrp;
QMap<QWidget*, QWidget*> m_moduleMap;
QWidget *m_currentWidget;
};

#endif // NORMALMODULE_H
11 changes: 11 additions & 0 deletions src/modules/wmmodemodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ WMModeModule::WMModeModule(QWidget *parent)
m_layout->addWidget(m_fashionWidget);

setLayout(m_layout);

updateSmaillIcon();
}

void WMModeModule::updateBigIcon()
Expand All @@ -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();
Expand Down
Loading

0 comments on commit b4a54bf

Please sign in to comment.