You've already forked ukui-panel
mirror of
https://github.com/ukui/ukui-panel.git
synced 2026-03-09 09:24:21 -07:00
get currect icon size when change panelsize
This commit is contained in:
@@ -58,6 +58,11 @@
|
||||
#include <KWindowSystem/NETWM>
|
||||
#include <QtX11Extras/QX11Info>
|
||||
|
||||
#define PANEL_SETTINGS "org.ukui.panel.settings"
|
||||
#define PANEL_SIZE_KEY "panelsize"
|
||||
#define ICON_SIZE_KEY "iconsize"
|
||||
#define PANEL_POSITION_KEY "panelposition"
|
||||
|
||||
bool UKUITaskButton::sDraggging = false;
|
||||
|
||||
/************************************************
|
||||
@@ -105,6 +110,15 @@ UKUITaskButton::UKUITaskButton(QString appName,const WId window, UKUITaskBar * t
|
||||
connect(mDNDTimer, SIGNAL(timeout()), this, SLOT(activateWithDraggable()));
|
||||
connect(UKUi::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(updateIcon()));
|
||||
connect(mParentTaskBar, &UKUITaskBar::iconByClassChanged, this, &UKUITaskButton::updateIcon);
|
||||
|
||||
const QByteArray id(PANEL_SETTINGS);
|
||||
gsettings = new QGSettings(id);
|
||||
connect(gsettings, &QGSettings::changed, this, [=] (const QString &key){
|
||||
if (key == PANEL_SIZE_KEY)
|
||||
{
|
||||
updateIcon();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/************************************************
|
||||
@@ -127,10 +141,12 @@ void UKUITaskButton::updateText()
|
||||
|
||||
/* int devicePixels = mPlugin->panel()->iconSize() * devicePixelRatioF()是由ico =KWindowSystem:ico(mwindow)更改的
|
||||
* 目的是为了能够显示正确的application-x-desktop的图标的大小
|
||||
*
|
||||
*/
|
||||
void UKUITaskButton::updateIcon()
|
||||
{
|
||||
QIcon ico;
|
||||
int mIconSize=mPlugin->panel()->iconSize();
|
||||
if (mParentTaskBar->isIconByClass())
|
||||
{
|
||||
ico = XdgIcon::fromTheme(QString::fromUtf8(KWindowInfo{mWindow, 0, NET::WM2WindowClass}.windowClassClass()).toLower());
|
||||
@@ -141,31 +157,15 @@ void UKUITaskButton::updateIcon()
|
||||
}
|
||||
if (ico.isNull())
|
||||
{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
int devicePixels = mPlugin->panel()->iconSize() * devicePixelRatioF();
|
||||
#if QT_VERSION >= 0x050600
|
||||
int devicePixels = mIconSize * devicePixelRatioF();
|
||||
#else
|
||||
int devicePixels = mPlugin->panel()->iconSize() * devicePixelRatio();
|
||||
int devicePixels = mIconSize * devicePixelRatio();
|
||||
#endif
|
||||
ico = KWindowSystem::icon(mWindow, devicePixels, devicePixels);
|
||||
}
|
||||
if(ico.isNull())
|
||||
{
|
||||
ico = XdgIcon::fromTheme("application-x-desktop");
|
||||
}
|
||||
|
||||
if(mIcon.isNull())
|
||||
{
|
||||
mIcon = ico;
|
||||
}
|
||||
// setIcon(ico.isNull() ? XdgIcon::fromTheme("application-x-desktop") : ico);
|
||||
setIcon(mIcon);
|
||||
|
||||
/*传入参数 bool 是开启 打开多个窗口 的样式*/
|
||||
// if(mButtonHash.size()>1)
|
||||
|
||||
// this->setStyle(new CustomStyle("taskbutton",true));
|
||||
// else
|
||||
// this->setStyle(new CustomStyle("taskbutton",false));
|
||||
setIcon(ico.isNull() ? QIcon::fromTheme("application-x-desktop") : ico);
|
||||
setIconSize(QSize(mIconSize,mIconSize));
|
||||
}
|
||||
|
||||
/************************************************
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#ifndef UKUITASKBUTTON_H
|
||||
#define UKUITASKBUTTON_H
|
||||
|
||||
#include <QGSettings/QGSettings>
|
||||
#include <QToolButton>
|
||||
#include <QProxyStyle>
|
||||
#include <QLabel>
|
||||
@@ -139,7 +140,7 @@ private:
|
||||
// Timer for when draggind something into a button (the button's window
|
||||
// must be activated so that the use can continue dragging to the window
|
||||
QTimer * mDNDTimer;
|
||||
|
||||
QGSettings *gsettings;
|
||||
private slots:
|
||||
void activateWithDraggable();
|
||||
|
||||
|
||||
@@ -217,8 +217,7 @@ void UKUITaskGroup::closeGroup()
|
||||
if (button->isOnDesktop(KWindowSystem::currentDesktop()))
|
||||
button->closeApplication();
|
||||
}
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0))
|
||||
#else
|
||||
for (UKUITaskWidget *button : qAsConst(mButtonHash) )
|
||||
if (button->isOnDesktop(KWindowSystem::currentDesktop()))
|
||||
button->closeApplication();
|
||||
@@ -435,8 +434,7 @@ int UKUITaskGroup::visibleButtonsCount() const
|
||||
if (btn->isVisibleTo(mPopup))
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0))
|
||||
#else
|
||||
for (UKUITaskWidget *btn : qAsConst(mButtonHash))
|
||||
if (btn->isVisibleTo(mPopup))
|
||||
i++;
|
||||
@@ -594,8 +592,7 @@ void UKUITaskGroup::refreshVisibility()
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
for(auto i=mButtonHash.begin();i!=mButtonHash.end();i++){
|
||||
UKUITaskWidget * btn=i.value();
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0))
|
||||
#else
|
||||
for(UKUITaskWidget * btn : qAsConst(mButtonHash)){
|
||||
#endif
|
||||
bool visible = taskbar->isShowOnlyOneDesktopTasks() ? btn->isOnDesktop(0 == showDesktop ? KWindowSystem::currentDesktop() : showDesktop) : true;
|
||||
|
||||
@@ -32,8 +32,9 @@
|
||||
|
||||
#define UKUI_PANEL_SETTINGS "org.ukui.panel.settings"
|
||||
#define SHOW_TASKVIEW "showtaskview"
|
||||
|
||||
TaskViewButton::TaskViewButton(){
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
TaskViewButton::~TaskViewButton(){
|
||||
}
|
||||
@@ -43,16 +44,18 @@ TaskView::TaskView(const IUKUIPanelPluginStartupInfo &startupInfo) :
|
||||
{
|
||||
mButton =new TaskViewButton();
|
||||
mButton->setStyle(new CustomStyle());
|
||||
mButton->setIcon(QIcon("/usr/share/ukui-panel/panel/img/taskview.svg"));
|
||||
// mButton->paintTooltipStyle();
|
||||
mButton->setIcon(QIcon::fromTheme("taskview",QIcon("/usr/share/ukui-panel/panel/img/taskview.svg")));
|
||||
mButton->setToolTip(tr("Show Taskview"));
|
||||
|
||||
/* hide/show taskview
|
||||
* Monitor gsettings to set TaskViewButton size
|
||||
*/
|
||||
const QByteArray id(UKUI_PANEL_SETTINGS);
|
||||
if(QGSettings::isSchemaInstalled(id))
|
||||
gsettings = new QGSettings(id);
|
||||
connect(gsettings, &QGSettings::changed, this, [=] (const QString &key){
|
||||
if(key==SHOW_TASKVIEW)
|
||||
realign();
|
||||
if(key==SHOW_TASKVIEW)
|
||||
realign();
|
||||
});
|
||||
|
||||
realign();
|
||||
@@ -63,7 +66,7 @@ TaskView::~TaskView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* 隐藏任务视图按钮的逻辑是将buttton的大小设置为0*/
|
||||
void TaskView::realign()
|
||||
{
|
||||
if(gsettings->get(SHOW_TASKVIEW).toBool())
|
||||
@@ -73,22 +76,27 @@ void TaskView::realign()
|
||||
mButton->setIconSize(QSize(panel()->iconSize(),panel()->iconSize()));
|
||||
}
|
||||
|
||||
/* 两种方式可调用任务视图
|
||||
* 1.调用Dbus接口
|
||||
* 2.调用二进制
|
||||
*/
|
||||
void TaskViewButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
const Qt::MouseButton b = event->button();
|
||||
QDBusInterface interface("org.ukui.WindowSwitch", "/org/ukui/WindowSwitch",
|
||||
"org.ukui.WindowSwitch",
|
||||
QDBusConnection::sessionBus());
|
||||
"org.ukui.WindowSwitch",
|
||||
QDBusConnection::sessionBus());
|
||||
if (!interface.isValid()) {
|
||||
qCritical() << QDBusConnection::sessionBus().lastError().message();
|
||||
}
|
||||
|
||||
if (Qt::LeftButton == b && interface.isValid())
|
||||
{
|
||||
//Two ways to call the taskview
|
||||
//system("ukui-window-switch --show-workspace");
|
||||
/* Call binary display task view
|
||||
* system("ukui-window-switch --show-workspace");
|
||||
*/
|
||||
|
||||
//调用远程的value方法
|
||||
/*调用远程的value方法*/
|
||||
QDBusReply<bool> reply = interface.call("handleWorkspace");
|
||||
if (reply.isValid()) {
|
||||
if (!reply.value())
|
||||
@@ -100,13 +108,3 @@ void TaskViewButton::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void TaskViewButton::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
qDebug()<<"mouse move enent";
|
||||
QWidget::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
void TaskViewButton::contextMenuEvent(QContextMenuEvent *event){
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#ifndef STARTMENU_H
|
||||
#define STARTMENU_H
|
||||
|
||||
#include "../panel/iukuipanelplugin.h"
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFrame>
|
||||
@@ -30,7 +29,6 @@
|
||||
#include <QToolButton>
|
||||
#include <XdgIcon>
|
||||
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
@@ -39,10 +37,11 @@
|
||||
#include <QPainter>
|
||||
#include <QGSettings>
|
||||
|
||||
#include "../panel/iukuipanelplugin.h"
|
||||
#include "../panel/plugin.h"
|
||||
#include "../panel/ukuipanel.h"
|
||||
#include "../panel/ukuicontrolstyle.h"
|
||||
#define DEFAULT_SHORTCUT "Alt+F1"
|
||||
|
||||
|
||||
class TaskViewButton:public UkuiToolButton
|
||||
{
|
||||
@@ -51,11 +50,7 @@ public:
|
||||
TaskViewButton();
|
||||
~TaskViewButton();
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
private:
|
||||
void paintTaskViewStyle();
|
||||
|
||||
};
|
||||
|
||||
@@ -69,13 +64,10 @@ public:
|
||||
virtual QWidget *widget() { return mButton; }
|
||||
virtual QString themeId() const { return QStringLiteral("taskview"); }
|
||||
void realign();
|
||||
virtual IUKUIPanelPlugin::Flags flags() const { return PreferRightAlignment | HaveConfigDialog ; }
|
||||
|
||||
private:
|
||||
TaskViewButton *mButton;
|
||||
QGSettings *gsettings;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class TaskViewLibrary: public QObject, public IUKUIPanelPluginLibrary
|
||||
|
||||
Reference in New Issue
Block a user