mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
add fashion mode
Change-Id: I9fb88a4356d049f18ce82cf91d756bc05c12ca4f
This commit is contained in:
parent
b727862b8e
commit
28f2745de3
@ -44,10 +44,11 @@ void DockItemController::itemMove(DockItem * const moveItem, DockItem * const re
|
||||
m_itemList.indexOf(replaceItem);
|
||||
|
||||
m_itemList.removeAt(moveIndex);
|
||||
emit itemRemoved(moveItem);
|
||||
// emit itemRemoved(moveItem);
|
||||
|
||||
m_itemList.insert(replaceIndex, moveItem);
|
||||
emit itemInserted(replaceIndex, moveItem);
|
||||
// emit itemInserted(replaceIndex, moveItem);
|
||||
emit itemMoved(moveItem, replaceIndex);
|
||||
|
||||
// for app move, index 0 is launcher item, need to pass it.
|
||||
if (moveItem->itemType() == DockItem::App)
|
||||
|
@ -19,8 +19,9 @@ public:
|
||||
const QList<DockItem *> itemList() const;
|
||||
|
||||
signals:
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
void itemInserted(const int index, DockItem *item) const;
|
||||
void itemRemoved(DockItem *item) const;
|
||||
void itemMoved(DockItem *item, const int index) const;
|
||||
|
||||
public slots:
|
||||
void itemMove(DockItem * const moveItem, DockItem * const replaceItem);
|
||||
|
@ -11,7 +11,6 @@
|
||||
int AppItem::IconBaseSize;
|
||||
QPoint AppItem::MousePressPos;
|
||||
DBusClientManager *AppItem::ClientInter = nullptr;
|
||||
//uint AppItem::ActiveWindowId = 0;
|
||||
|
||||
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
: DockItem(App, parent),
|
||||
@ -175,9 +174,6 @@ void AppItem::initClientManager()
|
||||
return;
|
||||
|
||||
ClientInter = new DBusClientManager(this);
|
||||
// connect(ClientInter, &DBusClientManager::ActiveWindowChanged, [&] (const uint wid) {
|
||||
// ActiveWindowId = wid;
|
||||
// });
|
||||
}
|
||||
|
||||
void AppItem::updateTitle()
|
||||
|
@ -47,7 +47,6 @@ private:
|
||||
static int IconBaseSize;
|
||||
static QPoint MousePressPos;
|
||||
static DBusClientManager *ClientInter;
|
||||
// static uint ActiveWindowId;
|
||||
};
|
||||
|
||||
#endif // APPITEM_H
|
||||
|
@ -26,6 +26,7 @@ MainPanel::MainPanel(QWidget *parent)
|
||||
|
||||
connect(m_itemController, &DockItemController::itemInserted, this, &MainPanel::itemInserted);
|
||||
connect(m_itemController, &DockItemController::itemRemoved, this, &MainPanel::itemRemoved);
|
||||
connect(m_itemController, &DockItemController::itemMoved, this, &MainPanel::itemMoved);
|
||||
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
@ -158,6 +159,14 @@ void MainPanel::itemRemoved(DockItem *item)
|
||||
m_itemLayout->removeWidget(item);
|
||||
}
|
||||
|
||||
void MainPanel::itemMoved(DockItem *item, const int index)
|
||||
{
|
||||
// remove old item
|
||||
m_itemLayout->removeWidget(item);
|
||||
// insert new position
|
||||
m_itemLayout->insertWidget(index, item);
|
||||
}
|
||||
|
||||
void MainPanel::itemDragStarted()
|
||||
{
|
||||
DragingItem = qobject_cast<DockItem *>(sender());
|
||||
|
@ -30,6 +30,7 @@ private slots:
|
||||
void adjustItemSize();
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
void itemMoved(DockItem *item, const int index);
|
||||
void itemDragStarted();
|
||||
|
||||
private:
|
||||
|
@ -82,6 +82,10 @@ DockSettings::DockSettings(QObject *parent)
|
||||
connect(&m_settingsMenu, &DMenu::triggered, this, &DockSettings::menuActionClicked);
|
||||
connect(m_dockInter, &DBusDock::PositionChanged, this, &DockSettings::positionChanged);
|
||||
connect(m_dockInter, &DBusDock::IconSizeChanged, this, &DockSettings::iconSizeChanged);
|
||||
connect(m_dockInter, &DBusDock::DisplayModeChanged, this, &DockSettings::displayModeChanged);
|
||||
|
||||
connect(m_itemController, &DockItemController::itemInserted, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
||||
connect(m_itemController, &DockItemController::itemRemoved, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
||||
|
||||
calculateWindowConfig();
|
||||
}
|
||||
@ -172,27 +176,87 @@ void DockSettings::iconSizeChanged()
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
void DockSettings::displayModeChanged()
|
||||
{
|
||||
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
||||
|
||||
calculateWindowConfig();
|
||||
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
void DockSettings::dockItemCountChanged()
|
||||
{
|
||||
if (m_displayMode == Dock::Efficient)
|
||||
return;
|
||||
|
||||
calculateWindowConfig();
|
||||
|
||||
emit windowGeometryChanged();
|
||||
}
|
||||
|
||||
void DockSettings::calculateWindowConfig()
|
||||
{
|
||||
const QRect primaryRect = m_displayInter->primaryRect();
|
||||
const int defaultHeight = AppItem::itemBaseHeight();
|
||||
const int defaultWidth = AppItem::itemBaseWidth();
|
||||
|
||||
switch (m_position)
|
||||
if (m_displayMode == Dock::Efficient)
|
||||
{
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(defaultHeight);
|
||||
m_mainWindowSize.setWidth(primaryRect.width());
|
||||
break;
|
||||
switch (m_position)
|
||||
{
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(defaultHeight);
|
||||
m_mainWindowSize.setWidth(primaryRect.width());
|
||||
break;
|
||||
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(primaryRect.height());
|
||||
m_mainWindowSize.setWidth(defaultWidth);
|
||||
break;
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(primaryRect.height());
|
||||
m_mainWindowSize.setWidth(defaultWidth);
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
else if (m_displayMode == Dock::Fashion)
|
||||
{
|
||||
int appItemCount = 0;
|
||||
int pluginItemCount = 0;
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
switch (item->itemType())
|
||||
{
|
||||
case DockItem::Launcher:
|
||||
case DockItem::App: ++appItemCount; break;
|
||||
case DockItem::Plugins: ++pluginItemCount; break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
const int perfectWidth = qMin(primaryRect.width(), defaultWidth * (appItemCount + pluginItemCount));
|
||||
const int perfectHeight = qMin(primaryRect.height(), defaultHeight * (appItemCount + pluginItemCount));
|
||||
switch (m_position)
|
||||
{
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(defaultHeight);
|
||||
m_mainWindowSize.setWidth(perfectWidth);
|
||||
break;
|
||||
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(perfectHeight);
|
||||
m_mainWindowSize.setWidth(defaultWidth);
|
||||
break;
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
|
||||
signals:
|
||||
void dataChanged() const;
|
||||
void windowGeometryChanged() const;
|
||||
|
||||
public slots:
|
||||
void updateGeometry();
|
||||
@ -39,6 +40,9 @@ private slots:
|
||||
void menuActionClicked(DAction *action);
|
||||
void positionChanged();
|
||||
void iconSizeChanged();
|
||||
void displayModeChanged();
|
||||
|
||||
void dockItemCountChanged();
|
||||
|
||||
private:
|
||||
void calculateWindowConfig();
|
||||
|
@ -68,33 +68,42 @@ void MainWindow::initConnections()
|
||||
{
|
||||
connect(m_displayInter, &DBusDisplay::PrimaryRectChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
connect(m_settings, &DockSettings::dataChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
connect(m_settings, &DockSettings::windowGeometryChanged, this, &MainWindow::updateGeometry);
|
||||
|
||||
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition);
|
||||
}
|
||||
|
||||
void MainWindow::updatePosition()
|
||||
{
|
||||
// all update operation need pass by timer
|
||||
Q_ASSERT(sender() == m_positionUpdateTimer);
|
||||
|
||||
clearStrutPartial();
|
||||
updateGeometry();
|
||||
setStrutPartial();
|
||||
}
|
||||
|
||||
void MainWindow::updateGeometry()
|
||||
{
|
||||
setFixedSize(m_settings->windowSize());
|
||||
m_mainPanel->updateDockPosition(m_settings->position());
|
||||
|
||||
const QRect primaryRect = m_displayInter->primaryRect();
|
||||
const int offsetX = (primaryRect.width() - width()) / 2;
|
||||
const int offsetY = (primaryRect.height() - height()) / 2;
|
||||
switch (m_settings->position())
|
||||
{
|
||||
case Top:
|
||||
move(primaryRect.topLeft().x() + offsetX, 0); break;
|
||||
case Left:
|
||||
move(primaryRect.topLeft()); break;
|
||||
move(primaryRect.topLeft().x(), offsetY); break;
|
||||
case Right:
|
||||
move(primaryRect.right() - width(), 0); break;
|
||||
move(primaryRect.right() - width(), offsetY); break;
|
||||
case Bottom:
|
||||
move(0, primaryRect.bottom() - height() + 1); break;
|
||||
move(offsetX, primaryRect.bottom() - height() + 1); break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
setStrutPartial();
|
||||
}
|
||||
|
||||
void MainWindow::clearStrutPartial()
|
||||
@ -121,7 +130,7 @@ void MainWindow::setStrutPartial()
|
||||
{
|
||||
case Position::Top:
|
||||
orientation = XcbMisc::OrientationTop;
|
||||
strut = r.bottom();
|
||||
strut = r.bottom() + 1;
|
||||
strutStart = r.left();
|
||||
strutEnd = r.right();
|
||||
break;
|
||||
|
@ -26,6 +26,7 @@ private:
|
||||
|
||||
private slots:
|
||||
void updatePosition();
|
||||
void updateGeometry();
|
||||
void clearStrutPartial();
|
||||
void setStrutPartial();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user