mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
remove plugin simple mode
Change-Id: Ib287e902fddee96d8d4f49f829eed7015aff3a44
This commit is contained in:
parent
e558e29a80
commit
5aa989debb
@ -142,29 +142,29 @@ void DockItem::showContextMenu()
|
||||
|
||||
void DockItem::showPopupTips()
|
||||
{
|
||||
QWidget * const content = popupTips();
|
||||
if (!content)
|
||||
return;
|
||||
// QWidget * const content = popupTips();
|
||||
// if (!content)
|
||||
// return;
|
||||
|
||||
DArrowRectangle *tips = PopupTips.get();
|
||||
QWidget *lastContent = tips->getContent();
|
||||
if (lastContent)
|
||||
lastContent->hide();
|
||||
// DArrowRectangle *tips = PopupTips.get();
|
||||
// QWidget *lastContent = tips->getContent();
|
||||
// if (lastContent)
|
||||
// lastContent->hide();
|
||||
|
||||
switch (DockPosition)
|
||||
{
|
||||
case Top: tips->setArrowDirection(DArrowRectangle::ArrowTop); break;
|
||||
case Bottom:tips->setArrowDirection(DArrowRectangle::ArrowBottom); break;
|
||||
case Left: tips->setArrowDirection(DArrowRectangle::ArrowLeft); break;
|
||||
case Right: tips->setArrowDirection(DArrowRectangle::ArrowRight); break;
|
||||
}
|
||||
tips->setContent(content);
|
||||
tips->setMargin(5);
|
||||
tips->setWidth(content->sizeHint().width());
|
||||
tips->setHeight(content->sizeHint().height());
|
||||
// switch (DockPosition)
|
||||
// {
|
||||
// case Top: tips->setArrowDirection(DArrowRectangle::ArrowTop); break;
|
||||
// case Bottom:tips->setArrowDirection(DArrowRectangle::ArrowBottom); break;
|
||||
// case Left: tips->setArrowDirection(DArrowRectangle::ArrowLeft); break;
|
||||
// case Right: tips->setArrowDirection(DArrowRectangle::ArrowRight); break;
|
||||
// }
|
||||
// tips->setContent(content);
|
||||
// tips->setMargin(5);
|
||||
// tips->setWidth(content->sizeHint().width());
|
||||
// tips->setHeight(content->sizeHint().height());
|
||||
|
||||
const QPoint p = popupMarkPoint();
|
||||
tips->show(p.x(), p.y());
|
||||
// const QPoint p = popupMarkPoint();
|
||||
// tips->show(p.x(), p.y());
|
||||
}
|
||||
|
||||
void DockItem::invokedMenuItem(const QString &itemId, const bool checked)
|
||||
@ -178,11 +178,6 @@ const QString DockItem::contextMenu() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
QWidget *DockItem::popupTips()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const QPoint DockItem::popupMarkPoint()
|
||||
{
|
||||
QPoint p;
|
||||
|
@ -51,7 +51,6 @@ protected:
|
||||
void showPopupTips();
|
||||
virtual void invokedMenuItem(const QString &itemId, const bool checked);
|
||||
virtual const QString contextMenu() const;
|
||||
virtual QWidget *popupTips();
|
||||
|
||||
private:
|
||||
const QPoint popupMarkPoint();
|
||||
|
@ -17,22 +17,8 @@ PluginsItem::PluginsItem(PluginsItemInterface* const pluginInter, const QString
|
||||
: DockItem(Plugins, parent),
|
||||
m_pluginInter(pluginInter),
|
||||
m_itemKey(itemKey),
|
||||
m_draging(false),
|
||||
m_simpleTips(new QLabel(this))
|
||||
m_draging(false)
|
||||
{
|
||||
m_pluginType = pluginInter->pluginType(itemKey);
|
||||
|
||||
m_simpleTips->setVisible(false);
|
||||
m_simpleTips->setAlignment(Qt::AlignCenter);
|
||||
m_simpleTips->setStyleSheet("QLabel {"
|
||||
"color:white;"
|
||||
"padding:5px 10px;"
|
||||
"font-size:14px;"
|
||||
"}");
|
||||
|
||||
if (m_pluginType == PluginsItemInterface::Simple)
|
||||
return;
|
||||
|
||||
// construct complex widget layout
|
||||
QWidget *centeralWidget = m_pluginInter->itemWidget(itemKey);
|
||||
Q_ASSERT(centeralWidget);
|
||||
@ -58,9 +44,6 @@ int PluginsItem::itemSortKey() const
|
||||
|
||||
void PluginsItem::detachPluginWidget()
|
||||
{
|
||||
if (m_pluginType == PluginsItemInterface::Simple)
|
||||
return;
|
||||
|
||||
QWidget *widget = m_pluginInter->itemWidget(m_itemKey);
|
||||
if (widget)
|
||||
widget->setParent(nullptr);
|
||||
@ -109,19 +92,25 @@ void PluginsItem::paintEvent(QPaintEvent *e)
|
||||
if (m_draging)
|
||||
return;
|
||||
|
||||
if (m_pluginType == PluginsItemInterface::Complex)
|
||||
if (!m_hover)
|
||||
return DockItem::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
// TODO: hover
|
||||
// const QPixmap pixmap =
|
||||
|
||||
const QIcon icon = m_pluginInter->itemIcon(m_itemKey);
|
||||
const QRect iconRect = perfectIconRect();
|
||||
const QPixmap pixmap = icon.pixmap(iconRect.size());
|
||||
// if (m_pluginType == PluginsItemInterface::Complex)
|
||||
// return DockItem::paintEvent(e);
|
||||
|
||||
painter.drawPixmap(iconRect, pixmap);
|
||||
// QPainter painter(this);
|
||||
|
||||
if (m_hover)
|
||||
painter.drawPixmap(iconRect, ImageFactory::lighterEffect(pixmap));
|
||||
// const QIcon icon = m_pluginInter->itemIcon(m_itemKey);
|
||||
// const QRect iconRect = perfectIconRect();
|
||||
// const QPixmap pixmap = icon.pixmap(iconRect.size());
|
||||
|
||||
// painter.drawPixmap(iconRect, pixmap);
|
||||
|
||||
// if (m_hover)
|
||||
// painter.drawPixmap(iconRect, ImageFactory::lighterEffect(pixmap));
|
||||
}
|
||||
|
||||
bool PluginsItem::eventFilter(QObject *o, QEvent *e)
|
||||
@ -133,36 +122,23 @@ bool PluginsItem::eventFilter(QObject *o, QEvent *e)
|
||||
return DockItem::eventFilter(o, e);
|
||||
}
|
||||
|
||||
QSize PluginsItem::sizeHint() const
|
||||
{
|
||||
if (m_pluginType == PluginsItemInterface::Complex)
|
||||
return DockItem::sizeHint();
|
||||
|
||||
// TODO: icon size on efficient mode
|
||||
return QSize(24, 24);
|
||||
}
|
||||
|
||||
QWidget *PluginsItem::popupTips()
|
||||
{
|
||||
if (m_pluginInter->tipsType(m_itemKey) == PluginsItemInterface::Complex)
|
||||
return m_pluginInter->itemTipsWidget(m_itemKey);
|
||||
// if (m_pluginInter->tipsType(m_itemKey) == PluginsItemInterface::Complex)
|
||||
// return m_pluginInter->itemTipsWidget(m_itemKey);
|
||||
|
||||
const QString tips = m_pluginInter->itemTipsString(m_itemKey);
|
||||
if (tips.isEmpty())
|
||||
return nullptr;
|
||||
// const QString tips = m_pluginInter->itemTipsString(m_itemKey);
|
||||
// if (tips.isEmpty())
|
||||
// return nullptr;
|
||||
|
||||
m_simpleTips->setText(tips);
|
||||
// m_simpleTips->setText(tips);
|
||||
|
||||
return m_simpleTips;
|
||||
// return m_simpleTips;
|
||||
}
|
||||
|
||||
void PluginsItem::startDrag()
|
||||
{
|
||||
QPixmap pixmap;
|
||||
if (m_pluginType == PluginsItemInterface::Simple)
|
||||
pixmap = m_pluginInter->itemIcon(m_itemKey).pixmap(perfectIconRect().size());
|
||||
else
|
||||
pixmap = grab();
|
||||
const QPixmap pixmap = grab();
|
||||
|
||||
m_draging = true;
|
||||
update();
|
||||
@ -183,13 +159,13 @@ void PluginsItem::startDrag()
|
||||
|
||||
void PluginsItem::mouseClicked()
|
||||
{
|
||||
const QString command = m_pluginInter->itemCommand(m_itemKey);
|
||||
if (!command.isEmpty())
|
||||
{
|
||||
QProcess *proc = new QProcess(this);
|
||||
// const QString command = m_pluginInter->itemCommand(m_itemKey);
|
||||
// if (!command.isEmpty())
|
||||
// {
|
||||
// QProcess *proc = new QProcess(this);
|
||||
|
||||
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
|
||||
// connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
|
||||
|
||||
proc->startDetached(command);
|
||||
}
|
||||
// proc->startDetached(command);
|
||||
// }
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ private:
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
bool eventFilter(QObject *o, QEvent *e);
|
||||
QSize sizeHint() const;
|
||||
|
||||
QWidget *popupTips();
|
||||
|
||||
@ -32,10 +31,8 @@ private:
|
||||
private:
|
||||
PluginsItemInterface * const m_pluginInter;
|
||||
const QString m_itemKey;
|
||||
PluginsItemInterface::ItemType m_pluginType;
|
||||
|
||||
bool m_draging;
|
||||
QLabel *m_simpleTips;
|
||||
|
||||
static QPoint MousePressPoint;
|
||||
};
|
||||
|
@ -8,13 +8,6 @@
|
||||
|
||||
class PluginsItemInterface
|
||||
{
|
||||
public:
|
||||
enum ItemType
|
||||
{
|
||||
Simple,
|
||||
Complex,
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~PluginsItemInterface() {}
|
||||
|
||||
@ -27,22 +20,13 @@ public:
|
||||
// dock position changed
|
||||
virtual void positionChanged(const Dock::Position position) {Q_UNUSED(position);}
|
||||
|
||||
// plugins type, simple icon or complex widget
|
||||
virtual ItemType pluginType(const QString &itemKey) {Q_UNUSED(itemKey); return Simple;}
|
||||
// simple string tips or popup widget
|
||||
virtual ItemType tipsType(const QString &itemKey) {Q_UNUSED(itemKey); return Simple;}
|
||||
// item sort key
|
||||
virtual int itemSortKey(const QString &itemKey) {Q_UNUSED(itemKey); return 0;}
|
||||
// reset sort key when plugins order changed
|
||||
virtual void setSortKey(const QString &itemKey, const int order) {Q_UNUSED(itemKey); Q_UNUSED(order);}
|
||||
|
||||
// if pluginType is complex widget mode, return a widget to plugins item
|
||||
virtual QWidget *itemWidget(const QString &itemKey) {Q_UNUSED(itemKey); return nullptr;}
|
||||
virtual QWidget *itemTipsWidget(const QString &itemKey) {Q_UNUSED(itemKey); return nullptr;}
|
||||
// if pluginType is simple icon mode, plugins need to implements these data source functions
|
||||
virtual const QIcon itemIcon(const QString &itemKey) {Q_UNUSED(itemKey); return QIcon();}
|
||||
virtual const QString itemTipsString(const QString &itemKey) {Q_UNUSED(itemKey); return QString();}
|
||||
virtual const QString itemCommand(const QString &itemKey) {Q_UNUSED(itemKey); return QString();}
|
||||
|
||||
protected:
|
||||
Dock::DisplayMode displayMode() const
|
||||
|
@ -31,20 +31,6 @@ const QString DatetimePlugin::pluginName() const
|
||||
return "datetime";
|
||||
}
|
||||
|
||||
PluginsItemInterface::ItemType DatetimePlugin::pluginType(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return Complex;
|
||||
}
|
||||
|
||||
PluginsItemInterface::ItemType DatetimePlugin::tipsType(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return Complex;
|
||||
}
|
||||
|
||||
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
||||
{
|
||||
m_proxyInter = proxyInter;
|
||||
|
@ -18,8 +18,6 @@ public:
|
||||
~DatetimePlugin();
|
||||
|
||||
const QString pluginName() const;
|
||||
ItemType pluginType(const QString &itemKey);
|
||||
ItemType tipsType(const QString &itemKey);
|
||||
void init(PluginProxyInterface *proxyInter);
|
||||
|
||||
int itemSortKey(const QString &itemKey) const;
|
||||
|
@ -16,13 +16,6 @@ const QString ShutdownPlugin::pluginName() const
|
||||
return "shutdown";
|
||||
}
|
||||
|
||||
PluginsItemInterface::ItemType ShutdownPlugin::pluginType(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return Complex;
|
||||
}
|
||||
|
||||
QWidget *ShutdownPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
@ -38,21 +31,6 @@ void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
|
||||
displayModeChanged(qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>());
|
||||
}
|
||||
|
||||
void ShutdownPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
||||
{
|
||||
if (displayMode == Dock::Fashion)
|
||||
m_icon.addFile(":/icons/resources/icons/fashion.svg");
|
||||
else
|
||||
m_icon.addFile(":/icons/resources/icons/normal.svg");
|
||||
}
|
||||
|
||||
const QIcon ShutdownPlugin::itemIcon(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::itemCommand(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
@ -16,20 +16,14 @@ public:
|
||||
|
||||
const QString pluginName() const;
|
||||
void init(PluginProxyInterface *proxyInter);
|
||||
void displayModeChanged(const Dock::DisplayMode displayMode);
|
||||
|
||||
ItemType pluginType(const QString &itemKey);
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
const QIcon itemIcon(const QString &itemKey);
|
||||
const QString itemCommand(const QString &itemKey);
|
||||
const QString itemTipsString(const QString &itemKey);
|
||||
|
||||
private:
|
||||
QIcon m_icon;
|
||||
PluginWidget *m_pluginWidget;
|
||||
|
||||
|
||||
DBusPower *m_powerInter;
|
||||
};
|
||||
|
||||
|
@ -37,20 +37,6 @@ void SystemTrayPlugin::displayModeChanged(const Dock::DisplayMode mode)
|
||||
switchToMode(mode);
|
||||
}
|
||||
|
||||
PluginsItemInterface::ItemType SystemTrayPlugin::pluginType(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return Complex;
|
||||
}
|
||||
|
||||
PluginsItemInterface::ItemType SystemTrayPlugin::tipsType(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return Complex;
|
||||
}
|
||||
|
||||
QWidget *SystemTrayPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
if (itemKey == FASHION_MODE_ITEM)
|
||||
|
@ -19,8 +19,6 @@ public:
|
||||
const QString pluginName() const;
|
||||
void init(PluginProxyInterface *proxyInter);
|
||||
void displayModeChanged(const Dock::DisplayMode mode);
|
||||
ItemType pluginType(const QString &itemKey);
|
||||
ItemType tipsType(const QString &itemKey);
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
QWidget *itemTipsWidget(const QString &itemKey);
|
||||
|
Loading…
x
Reference in New Issue
Block a user