OSDN Git Service

kdeplasma-addons: adjust the size of the kolourpicker color button icon based on...
authorIvailo Monev <xakepa10@gmail.com>
Mon, 17 Jul 2023 05:30:43 +0000 (08:30 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 17 Jul 2023 05:30:43 +0000 (08:30 +0300)
otherwise if the applet is resized to, say, 100x100 the icon would be still
16x16 - very small for applet with a 100x100 size

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kdeplasma-addons/applets/kolourpicker/kolourpicker.cpp

index 84caa95..4ba1927 100644 (file)
@@ -152,6 +152,7 @@ public:
     ColorButton(QGraphicsWidget *parent);
 
 protected:
+    void resizeEvent(QGraphicsSceneResizeEvent *event) final;
     void dragEnterEvent(QGraphicsSceneDragDropEvent *event) final;
     void dragMoveEvent(QGraphicsSceneDragDropEvent *event) final;
     void dropEvent(QGraphicsSceneDragDropEvent *event) final;
@@ -191,6 +192,15 @@ void ColorButton::dropEvent(QGraphicsSceneDragDropEvent *event)
     picker->addColor(color);
 }
 
+void ColorButton::resizeEvent(QGraphicsSceneResizeEvent *event)
+{
+    const QSizeF sizef = size();
+    const int minsize = qRound(qMin(sizef.width(), sizef.height())) - 4;
+    nativeWidget()->setIconSize(QSize(minsize, minsize));
+    Plasma::ToolButton::resizeEvent(event);
+}
+
+
 Kolourpicker::Kolourpicker(QObject *parent, const QVariantList &args)
     : Plasma::Applet(parent, args),
       m_grabWidget(0)