Skip to content

Commit

Permalink
feat: add base Normal window
Browse files Browse the repository at this point in the history
- Add module interface

Change-Id: I3554094c7c339d53ea20338f1b6a5031975a1cb3
  • Loading branch information
justforlxz committed Mar 1, 2018
1 parent a3fcf55 commit 1dba994
Show file tree
Hide file tree
Showing 19 changed files with 331 additions and 55 deletions.
3 changes: 3 additions & 0 deletions dde-introduction.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
<file>resources/fashion_mode_big@2x.png</file>
<file>resources/fashion_mode_small.png</file>
<file>resources/fashion_mode_small@2x.png</file>
<file>resources/config.json</file>
<file>resources/list_select.png</file>
<file>resources/list_select@2x.png</file>
</qresource>
</RCC>
43 changes: 43 additions & 0 deletions resources/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"groups": [
{
"key": "introduce",
"name": "introduce",
"groups": [
{
"key": "introduce",
"name": "introduce",
"options": [
{
"key": "DesktopMode",
"name": "DesktopMode",
"type": "desktopMode"
}
]
},
{
"key": "desktopmode",
"name": "desktopmode",
"options": [
{
"key": "wmmode",
"name": "wmmode",
"type": "wmMode"
}
]
},
{
"key": "iconmode",
"name": "iconmode",
"options": [
{
"key": "iconmode",
"name": "iconmode",
"type": "iconMode"
}
]
}
]
}
]
}
Binary file added resources/list_select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/list_select@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include "mainwindow.h"

#include "normalwindow.h"
#include <DApplication>
#include <QDebug>

Expand All @@ -42,5 +42,9 @@ int main(int argc, char *argv[])
w.moveToCenter();
w.exec();

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

return 0;
}
18 changes: 15 additions & 3 deletions src/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ void MainWindow::updateModule(const int index)
case 4:
m_current = initIconModule();
break;
case 5:
close();
break;
default:
break;
}
Expand Down Expand Up @@ -148,21 +151,30 @@ BaseModuleWidget *MainWindow::initVideoWidgt()

BaseModuleWidget *MainWindow::initDesktopModeModule()
{
BaseModuleWidget* w = new BaseModuleWidget(new DesktopModeModule, m_fakerWidget);
DesktopModeModule *module = new DesktopModeModule;
module->updateBigIcon();

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"));
return w;
}

BaseModuleWidget *MainWindow::initWMModeModule()
{
BaseModuleWidget* w = new BaseModuleWidget(new WMModeModule, m_fakerWidget);
WMModeModule *module = new WMModeModule;
module->updateBigIcon();

BaseModuleWidget* w = new BaseModuleWidget(module, m_fakerWidget);
return w;
}

BaseModuleWidget *MainWindow::initIconModule()
{
BaseModuleWidget* w = new BaseModuleWidget(new IconModule, m_fakerWidget);
IconModule *module = new IconModule;
module->updateBigIcon();

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"));
return w;
Expand Down
9 changes: 7 additions & 2 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct IconStruct {
QString Id;
QString Path;
bool Deletable;
QPixmap Pixmap;
QString Pixmap;

bool operator ==(const IconStruct &icon) const {
return Id == icon.Id;
Expand All @@ -50,7 +50,7 @@ struct IconStruct {
Icon.Id = object["Id"].toString();
Icon.Path = object["Path"].toString();
Icon.Deletable = object["Deletable"].toBool();
Icon.Pixmap = QPixmap(object["Pixmap"].toString());
Icon.Pixmap = object["Pixmap"].toString();

return Icon;
}
Expand All @@ -72,6 +72,11 @@ class Model : public QObject
WM_3D
};

enum IconType {
Big,
Small
};

inline IconStruct currentIcon() { return m_currentIcon; }
inline QList<IconStruct> iconList() { return m_iconList; }
inline WMType wmType() const { return m_wmType; }
Expand Down
19 changes: 13 additions & 6 deletions src/modules/desktopmodemodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
#include "desktopmodemodule.h"

DesktopModeModule::DesktopModeModule(QWidget *parent)
: QFrame(parent)
: ModuleInterface(parent)
, m_layout(new QHBoxLayout(this))
, m_model(Model::Instance())
, m_worker(Worker::Instance())
, m_efficientWidget(new BaseWidget(this))
, m_fashionWidget(new BaseWidget(this))
{
m_efficientWidget->setTitle(tr("Efficient Mode"));
m_fashionWidget->setTitle(tr("Fashion Mode"));

m_efficientWidget->setPixmap(":/resources/effective_mode_big.png");
m_fashionWidget->setPixmap(":/resources/fashion_mode_big.png");

connect(m_model, &Model::desktopModeChanged, this, &DesktopModeModule::onDesktopTypeChanged);
connect(m_fashionWidget, &BaseWidget::clicked, this, [=] {
m_worker->setDesktopMode(Model::FashionMode);
Expand Down Expand Up @@ -65,4 +60,16 @@ void DesktopModeModule::onDesktopTypeChanged(Model::DesktopMode mode)
}
}

void DesktopModeModule::updateBigIcon()
{
m_efficientWidget->setPixmap(":/resources/effective_mode_big.png");
m_fashionWidget->setPixmap(":/resources/fashion_mode_big.png");
}

void DesktopModeModule::updateSmaillIcon()
{
m_efficientWidget->setPixmap(":/resources/effective_mode_small.png");
m_fashionWidget->setPixmap(":/resources/fashion_mode_small.png");
}


9 changes: 6 additions & 3 deletions src/modules/desktopmodemodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,29 @@
#ifndef DESKTOPMODEMODULE_H
#define DESKTOPMODEMODULE_H

#include "moduleinterface.h"
#include "../widgets/basewidget.h"
#include "../model.h"
#include "../worker.h"

#include <QFrame>
#include <QHBoxLayout>

class DesktopModeModule : public QFrame
class DesktopModeModule : public ModuleInterface
{
Q_OBJECT
public:
explicit DesktopModeModule(QWidget *parent = nullptr);

void updateBigIcon() Q_DECL_OVERRIDE;
void updateSmaillIcon() Q_DECL_OVERRIDE;

private Q_SLOTS:
void onDesktopTypeChanged(Model::DesktopMode mode);


private:
QHBoxLayout* m_layout;
Model* m_model;
Worker* m_worker;
BaseWidget* m_efficientWidget;
BaseWidget* m_fashionWidget;
};
Expand Down
37 changes: 20 additions & 17 deletions src/modules/iconmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#include "iconmodule.h"

#include <QImageReader>

IconModule::IconModule(QWidget *parent)
: QScrollArea(parent)
: ModuleInterface(parent)
, m_layout(new DFlowLayout(this))
, m_model(Model::Instance())
, m_worker(Worker::Instance())
{
connect(m_model, &Model::iconAdded, this, &IconModule::addIcon);
connect(m_model, &Model::iconRemoved, this, &IconModule::removeIcon);
Expand All @@ -37,19 +37,7 @@ IconModule::IconModule(QWidget *parent)
m_layout->setSpacing(20);
m_layout->setContentsMargins(15, 0, 10, 0);

QWidget *content = new QWidget;
content->setLayout(m_layout);

setWidget(content);
setWidgetResizable(true);
setFocusPolicy(Qt::NoFocus);
setFrameStyle(QFrame::NoFrame);
setContentsMargins(0, 0, 0, 0);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setStyleSheet("background-color:transparent;");

setFixedSize(750, 300);
setLayout(m_layout);
}

void IconModule::addIcon(const IconStruct &icon)
Expand All @@ -59,7 +47,12 @@ void IconModule::addIcon(const IconStruct &icon)
}

BaseWidget *base = new BaseWidget(this);
base->setPixmap(icon.Pixmap);

QPixmap pixmap(icon.Pixmap);
pixmap.setDevicePixelRatio(devicePixelRatioF());

base->setPixmap(pixmap);
base->setTitle(icon.Id);

connect(base, &BaseWidget::clicked, this, [=] {
m_worker->setIcon(icon);
Expand Down Expand Up @@ -90,3 +83,13 @@ void IconModule::currentIconChanged(const IconStruct &icon)
map.next();
}
}

void IconModule::updateBigIcon()
{
setFixedWidth(750);
}

void IconModule::updateSmaillIcon()
{

}
8 changes: 5 additions & 3 deletions src/modules/iconmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef ICONMODULE_H
#define ICONMODULE_H

#include "moduleinterface.h"
#include "../widgets/basewidget.h"
#include "../model.h"
#include "../worker.h"
Expand All @@ -29,21 +30,22 @@

DWIDGET_USE_NAMESPACE

class IconModule : public QScrollArea
class IconModule : public ModuleInterface
{
Q_OBJECT
public:
explicit IconModule(QWidget *parent = nullptr);

void updateBigIcon() Q_DECL_OVERRIDE;
void updateSmaillIcon() Q_DECL_OVERRIDE;

private Q_SLOTS:
void addIcon(const IconStruct &icon);
void removeIcon(const IconStruct &icon);
void currentIconChanged(const IconStruct &icon);

private:
DFlowLayout* m_layout;
Model* m_model;
Worker* m_worker;
QMap<IconStruct, BaseWidget*> m_iconList;
};

Expand Down
41 changes: 41 additions & 0 deletions src/modules/moduleinterface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 "moduleinterface.h"

ModuleInterface::ModuleInterface(QWidget *parent)
: QFrame(parent)
, m_model(Model::Instance())
, m_worker(Worker::Instance())
{

}

void ModuleInterface::setIconType(Model::IconType type)
{
switch (type) {
case Model::Big:
updateBigIcon();
break;
case Model::Small:
updateSmaillIcon();
break;
default:
break;
}
}
Loading

0 comments on commit 1dba994

Please sign in to comment.