mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat(panel):添加一个新的任务栏框架代码。
说明: 代码编程规范
This commit is contained in:
parent
ef232eea04
commit
b7284a6ea3
156
frame/panel/mainpanelcontrol.cpp
Normal file
156
frame/panel/mainpanelcontrol.cpp
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd.
|
||||||
|
*
|
||||||
|
* Author: xuwenw <xuwenw@xuwenw.so>
|
||||||
|
*
|
||||||
|
* Maintainer: xuwenw <xuwenw@xuwenw.so>
|
||||||
|
*
|
||||||
|
* 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 "mainpanelcontrol.h"
|
||||||
|
|
||||||
|
#include <DAnchors>
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
|
MainPanelControl::MainPanelControl(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, m_mainPanelLayout(new QBoxLayout(QBoxLayout::LeftToRight, this))
|
||||||
|
, m_fixedAreaWidget(new QWidget(this))
|
||||||
|
, m_appAreaWidget(new QWidget(this))
|
||||||
|
, m_trayAreaWidget(new QWidget(this))
|
||||||
|
, m_pluginAreaWidget(new QWidget(this))
|
||||||
|
, m_fixedAreaLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
||||||
|
, m_trayAreaLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
||||||
|
, m_pluginLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
||||||
|
, m_appAreaSonWidget(new QWidget(this))
|
||||||
|
, m_appAreaSonLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
||||||
|
, m_position(Qt::TopEdge)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
updateMainPanelLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
MainPanelControl::~MainPanelControl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::init()
|
||||||
|
{
|
||||||
|
m_mainPanelLayout->setMargin(0);
|
||||||
|
m_mainPanelLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_fixedAreaLayout->setMargin(0);
|
||||||
|
m_fixedAreaLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_pluginLayout->setMargin(0);
|
||||||
|
m_pluginLayout->setSpacing(0);
|
||||||
|
m_pluginLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_trayAreaLayout->setMargin(0);
|
||||||
|
m_trayAreaLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_appAreaSonLayout->setMargin(0);
|
||||||
|
m_appAreaSonLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_mainPanelLayout->addWidget(m_fixedAreaWidget);
|
||||||
|
m_fixedAreaWidget->setLayout(m_fixedAreaLayout);
|
||||||
|
m_mainPanelLayout->addWidget(m_appAreaWidget);
|
||||||
|
m_mainPanelLayout->addWidget(m_trayAreaWidget);
|
||||||
|
m_trayAreaWidget->setLayout(m_trayAreaLayout);
|
||||||
|
m_mainPanelLayout->addWidget(m_pluginAreaWidget);
|
||||||
|
m_pluginAreaWidget->setLayout(m_pluginLayout);
|
||||||
|
m_appAreaSonWidget->setLayout(m_appAreaSonLayout);
|
||||||
|
|
||||||
|
DAnchors<QWidget> anchors(m_appAreaSonWidget);
|
||||||
|
anchors.setAnchor(Qt::AnchorHorizontalCenter, this, Qt::AnchorHorizontalCenter);
|
||||||
|
anchors.setAnchor(Qt::AnchorVerticalCenter, this, Qt::AnchorVerticalCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::updateMainPanelLayout()
|
||||||
|
{
|
||||||
|
switch (m_position) {
|
||||||
|
case Qt::TopEdge:
|
||||||
|
case Qt::BottomEdge:
|
||||||
|
m_fixedAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
|
m_appAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
m_pluginAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
|
m_trayAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
|
m_mainPanelLayout->setDirection(QBoxLayout::LeftToRight);
|
||||||
|
m_fixedAreaLayout->setDirection(QBoxLayout::LeftToRight);
|
||||||
|
m_pluginLayout->setDirection(QBoxLayout::LeftToRight);
|
||||||
|
m_trayAreaLayout->setDirection(QBoxLayout::LeftToRight);
|
||||||
|
m_appAreaSonLayout->setDirection(QBoxLayout::LeftToRight);
|
||||||
|
break;
|
||||||
|
case Qt::RightEdge:
|
||||||
|
case Qt::LeftEdge:
|
||||||
|
m_fixedAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
m_appAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
m_pluginAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
m_trayAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
m_mainPanelLayout->setDirection(QBoxLayout::TopToBottom);
|
||||||
|
m_fixedAreaLayout->setDirection(QBoxLayout::TopToBottom);
|
||||||
|
m_pluginLayout->setDirection(QBoxLayout::TopToBottom);
|
||||||
|
m_trayAreaLayout->setDirection(QBoxLayout::TopToBottom);
|
||||||
|
m_appAreaSonLayout->setDirection(QBoxLayout::TopToBottom);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, &MainPanelControl::updateAppAreaSonWidgetSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::addFixedAreaItem(QWidget *wdg)
|
||||||
|
{
|
||||||
|
m_fixedAreaLayout->addWidget(wdg, 0, Qt::AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::addAppAreaItem(QWidget *wdg)
|
||||||
|
{
|
||||||
|
m_appAreaSonLayout->addWidget(wdg, 0, Qt::AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::addTrayAreaItem(QWidget *wdg)
|
||||||
|
{
|
||||||
|
m_trayAreaLayout->addWidget(wdg, 0, Qt::AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::addPluginAreaItem(QWidget *wdg)
|
||||||
|
{
|
||||||
|
m_pluginLayout->addWidget(wdg, 0, Qt::AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
updateAppAreaSonWidgetSize();
|
||||||
|
|
||||||
|
return QWidget::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::updateAppAreaSonWidgetSize()
|
||||||
|
{
|
||||||
|
if ((m_position == Qt::TopEdge) || (m_position == Qt::BottomEdge)) {
|
||||||
|
m_appAreaSonWidget->setMaximumHeight(QWIDGETSIZE_MAX);
|
||||||
|
m_appAreaSonWidget->setMaximumWidth(qMin((m_appAreaWidget->geometry().right() - width() / 2) * 2, m_appAreaWidget->width()));
|
||||||
|
} else {
|
||||||
|
m_appAreaSonWidget->setMaximumWidth(QWIDGETSIZE_MAX);
|
||||||
|
m_appAreaSonWidget->setMaximumHeight(qMin((m_appAreaWidget->geometry().bottom() - height() / 2) * 2, m_appAreaWidget->height()));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_appAreaSonWidget->adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainPanelControl::setPositonValue(const Qt::Edge val)
|
||||||
|
{
|
||||||
|
m_position = val;
|
||||||
|
}
|
62
frame/panel/mainpanelcontrol.h
Normal file
62
frame/panel/mainpanelcontrol.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd.
|
||||||
|
*
|
||||||
|
* Author: xuwenw <xuwenw@xuwenw.so>
|
||||||
|
*
|
||||||
|
* Maintainer: <@xuwenw.so>
|
||||||
|
*
|
||||||
|
* 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 MAINPANELCONTROL_H
|
||||||
|
#define MAINPANELCONTROL_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QBoxLayout>
|
||||||
|
|
||||||
|
class MainPanelControl : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MainPanelControl(QWidget *parent = 0);
|
||||||
|
~MainPanelControl();
|
||||||
|
|
||||||
|
void addFixedAreaItem(QWidget *wdg);
|
||||||
|
void addAppAreaItem(QWidget *wdg);
|
||||||
|
void addTrayAreaItem(QWidget *wdg);
|
||||||
|
void addPluginAreaItem(QWidget *wdg);
|
||||||
|
void setPositonValue(const Qt::Edge val);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void updateAppAreaSonWidgetSize();
|
||||||
|
void updateMainPanelLayout();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QBoxLayout *m_mainPanelLayout;
|
||||||
|
QWidget *m_fixedAreaWidget;
|
||||||
|
QWidget *m_appAreaWidget;
|
||||||
|
QWidget *m_trayAreaWidget;
|
||||||
|
QWidget *m_pluginAreaWidget;
|
||||||
|
QBoxLayout *m_fixedAreaLayout;
|
||||||
|
QBoxLayout *m_trayAreaLayout;
|
||||||
|
QBoxLayout *m_pluginLayout;
|
||||||
|
QWidget *m_appAreaSonWidget;
|
||||||
|
QBoxLayout *m_appAreaSonLayout;
|
||||||
|
Qt::Edge m_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAINPANELCONTROL_H
|
Loading…
x
Reference in New Issue
Block a user