mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
set plugins item size
Change-Id: I8d03a403b576927cb475611bb5c7d50a933d0d21
This commit is contained in:
parent
98f0c75943
commit
1c1228a875
@ -55,12 +55,15 @@ void DockItemController::itemMove(DockItem * const moveItem, DockItem * const re
|
||||
DockItemController::DockItemController(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_appInter(new DBusDock(this)),
|
||||
m_pluginsInter(new DockPluginsController(this))
|
||||
m_pluginsInter(new DockPluginsController(this)),
|
||||
m_placeholderItem(new PlaceholderItem)
|
||||
{
|
||||
m_placeholderItem->hide();
|
||||
|
||||
m_itemList.append(new LauncherItem);
|
||||
for (auto entry : m_appInter->entries())
|
||||
m_itemList.append(new AppItem(entry));
|
||||
m_itemList.append(new PlaceholderItem);
|
||||
m_itemList.append(m_placeholderItem);
|
||||
|
||||
connect(m_appInter, &DBusDock::EntryAdded, this, &DockItemController::appItemAdded);
|
||||
connect(m_appInter, &DBusDock::EntryRemoved, this, &DockItemController::appItemRemoved);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "dbus/dbusdock.h"
|
||||
#include "item/dockitem.h"
|
||||
#include "item/placeholderitem.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@ -37,6 +38,7 @@ private:
|
||||
|
||||
DBusDock *m_appInter;
|
||||
DockPluginsController *m_pluginsInter;
|
||||
PlaceholderItem *m_placeholderItem;
|
||||
|
||||
static DockItemController *INSTANCE;
|
||||
};
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include "placeholderitem.h"
|
||||
|
||||
#include <QPaintEvent>
|
||||
|
||||
PlaceholderItem::PlaceholderItem(QWidget *parent)
|
||||
: DockItem(Placeholder, parent)
|
||||
{
|
||||
setBaseSize(0, 0);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
@ -11,8 +12,3 @@ void PlaceholderItem::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
QWidget::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void PlaceholderItem::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ public:
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
};
|
||||
|
||||
#endif // PLACEHOLDERITEM_H
|
||||
|
@ -20,7 +20,7 @@ int main(int argc, char *argv[])
|
||||
app.setApplicationVersion("2.0");
|
||||
|
||||
MainWindow mw;
|
||||
mw.show();
|
||||
QTimer::singleShot(500, &mw, &MainWindow::show);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ DockItem *MainPanel::DragingItem = nullptr;
|
||||
MainPanel::MainPanel(QWidget *parent)
|
||||
: QFrame(parent),
|
||||
m_position(Dock::Top),
|
||||
m_itemLayout(new QBoxLayout(QBoxLayout::LeftToRight, this)),
|
||||
m_displayMode(Dock::Fashion),
|
||||
m_itemLayout(new QBoxLayout(QBoxLayout::LeftToRight)),
|
||||
|
||||
m_itemAdjustTimer(new QTimer(this)),
|
||||
m_itemController(DockItemController::instance(this))
|
||||
@ -60,6 +61,8 @@ void MainPanel::updateDockPosition(const Position dockPosition)
|
||||
|
||||
void MainPanel::updateDockDisplayMode(const DisplayMode displayMode)
|
||||
{
|
||||
m_displayMode = displayMode;
|
||||
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
@ -170,8 +173,29 @@ void MainPanel::adjustItemSize()
|
||||
totalHeight += itemSize.height();
|
||||
break;
|
||||
case DockItem::Plugins:
|
||||
totalWidth += item->sizeHint().width();
|
||||
totalHeight += item->sizeHint().height();
|
||||
if (m_displayMode == Fashion)
|
||||
{
|
||||
item->setFixedSize(itemSize);
|
||||
++totalAppItemCount;
|
||||
totalWidth += itemSize.width();
|
||||
totalHeight += itemSize.height();
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setFixedSize(item->sizeHint());
|
||||
if (m_position == Dock::Top || m_position == Dock::Bottom)
|
||||
{
|
||||
item->setFixedHeight(itemSize.height());
|
||||
item->setFixedWidth(item->sizeHint().width());
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setFixedHeight(item->sizeHint().height());
|
||||
item->setFixedWidth(itemSize.width());
|
||||
}
|
||||
totalWidth += item->sizeHint().width();
|
||||
totalHeight += item->sizeHint().height();
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
@ -218,18 +242,23 @@ void MainPanel::adjustItemSize()
|
||||
|
||||
for (auto item : itemList)
|
||||
{
|
||||
if (item->itemType() != DockItem::App && item->itemType() != DockItem::Launcher)
|
||||
if (item->itemType() == DockItem::Placeholder)
|
||||
continue;
|
||||
if (item->itemType() == DockItem::Plugins)
|
||||
if (m_displayMode != Dock::Fashion)
|
||||
continue;
|
||||
|
||||
switch (m_position)
|
||||
{
|
||||
case Dock::Top:
|
||||
case Dock::Bottom:
|
||||
item->setFixedWidth(item->width() - decrease - bool(extraDecrease));
|
||||
break;
|
||||
|
||||
case Dock::Left:
|
||||
case Dock::Right:
|
||||
item->setFixedHeight(item->height() - decrease - bool(extraDecrease));
|
||||
break;
|
||||
}
|
||||
|
||||
if (extraDecrease)
|
||||
|
@ -37,6 +37,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Position m_position;
|
||||
DisplayMode m_displayMode;
|
||||
QBoxLayout *m_itemLayout;
|
||||
|
||||
QTimer *m_itemAdjustTimer;
|
||||
|
@ -238,22 +238,39 @@ void DockSettings::calculateWindowConfig()
|
||||
}
|
||||
else if (m_displayMode == Dock::Fashion)
|
||||
{
|
||||
int perfectWidth = 0;
|
||||
int perfectHeight = 0;
|
||||
// int perfectWidth = 0;
|
||||
// int perfectHeight = 0;
|
||||
// const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
// for (auto item : itemList)
|
||||
// {
|
||||
// switch (item->itemType())
|
||||
// {
|
||||
// case DockItem::Launcher:
|
||||
// case DockItem::App: perfectWidth += defaultWidth;
|
||||
// perfectHeight += defaultHeight; break;
|
||||
// case DockItem::Plugins: perfectWidth += item->sizeHint().width();
|
||||
// perfectHeight += item->sizeHint().height(); break;
|
||||
// default:;
|
||||
// }
|
||||
// }
|
||||
|
||||
int visibleItemCount = 0;
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
switch (item->itemType())
|
||||
{
|
||||
case DockItem::Launcher:
|
||||
case DockItem::App: perfectWidth += defaultWidth;
|
||||
perfectHeight += defaultHeight; break;
|
||||
case DockItem::Plugins: perfectWidth += item->sizeHint().width();
|
||||
perfectHeight += item->sizeHint().height(); break;
|
||||
case DockItem::App:
|
||||
case DockItem::Plugins:
|
||||
++visibleItemCount;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
const int perfectWidth = visibleItemCount * defaultWidth;
|
||||
const int perfectHeight = visibleItemCount * defaultHeight;
|
||||
const int calcWidth = qMin(m_primaryRect.width(), perfectWidth);
|
||||
const int calcHeight = qMin(m_primaryRect.height(), perfectHeight);
|
||||
switch (m_position)
|
||||
|
@ -21,6 +21,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
initComponents();
|
||||
initConnections();
|
||||
|
||||
m_mainPanel->setFixedSize(m_settings->windowSize());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -8,12 +8,15 @@ DatetimePlugin::DatetimePlugin(QObject *parent)
|
||||
m_timeLabel->setAlignment(Qt::AlignCenter);
|
||||
m_timeLabel->setStyleSheet("color:white;"
|
||||
"background-color:black;"
|
||||
"padding:5px;"
|
||||
"font-size:12px;");
|
||||
|
||||
m_refershTimer->setInterval(1000);
|
||||
m_refershTimer->start();
|
||||
|
||||
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::refershTime);
|
||||
|
||||
refershTime();
|
||||
}
|
||||
|
||||
DatetimePlugin::~DatetimePlugin()
|
||||
|
Loading…
x
Reference in New Issue
Block a user