[neon/backports-jammy/kcolorpicker] /: New upstream version 0.1.5

Boyuan Yang null at kde.org
Tue Jan 16 14:07:27 GMT 2024


Git commit ce285e8621aa86ca64b242cb7dd5648dbdd2d120 by Boyuan Yang.
Committed on 30/03/2021 at 15:47.
Pushed by jriddell into branch 'master'.

New upstream version 0.1.5

M  +2    -0    CMakeLists.txt
M  +1    -0    src/CMakeLists.txt
M  +1    -1    src/PopupMenu.cpp
M  +2    -0    src/buttons/AbstractPopupMenuButton.h
A  +58   -0    src/common/ScaledSizeProvider.cpp     [License: LGPL (v3+)]
C  +20   -18   src/common/ScaledSizeProvider.h [from: src/buttons/AbstractPopupMenuButton.h - 058% similarity]
M  +3    -1    tests/buttons/ColorButtonTest.h

https://invent.kde.org/neon/backports-jammy/kcolorpicker/-/commit/ce285e8621aa86ca64b242cb7dd5648dbdd2d120

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 24f793b..14a1bfc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,6 +18,8 @@ find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Widgets)
 include(GNUInstallDirs)
 include(FeatureSummary)
 
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
 add_subdirectory(src)
 
 if (BUILD_EXAMPLE)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6650eeb..250bf85 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,6 +5,7 @@ set(KCOLORPICKER_SRCS
         ${CMAKE_CURRENT_SOURCE_DIR}/buttons/AbstractPopupMenuButton.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/buttons/ColorButton.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/buttons/ColorDialogButton.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/common/ScaledSizeProvider.cpp
         )
 
 set(KCOLORPICKER_SRCS ${KCOLORPICKER_SRCS} PARENT_SCOPE)
diff --git a/src/PopupMenu.cpp b/src/PopupMenu.cpp
index e98e2d5..e8f6675 100644
--- a/src/PopupMenu.cpp
+++ b/src/PopupMenu.cpp
@@ -76,7 +76,7 @@ void PopupMenu::generateGrid()
 
 ColorButton *PopupMenu::createButton(const QColor &color)
 {
-	auto icon = IconCreator::createIcon(color, QSize(25, 25));
+	auto icon = IconCreator::createIcon(color, ScaledSizeProvider::scaledSize(QSize(25, 25)));
 	auto button = new ColorButton(icon, color);
 	return button;
 }
diff --git a/src/buttons/AbstractPopupMenuButton.h b/src/buttons/AbstractPopupMenuButton.h
index 5a2b81b..63a0967 100644
--- a/src/buttons/AbstractPopupMenuButton.h
+++ b/src/buttons/AbstractPopupMenuButton.h
@@ -25,6 +25,8 @@
 #include <QPaintEvent>
 #include <QStyleOption>
 
+#include "src/common/ScaledSizeProvider.h"
+
 namespace kColorPicker {
 
 class AbstractPopupMenuButton : public QToolButton
diff --git a/src/common/ScaledSizeProvider.cpp b/src/common/ScaledSizeProvider.cpp
new file mode 100644
index 0000000..c4ff99c
--- /dev/null
+++ b/src/common/ScaledSizeProvider.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2021 Damir Porobic <damir.porobic at gmx.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "ScaledSizeProvider.h"
+
+namespace kColorPicker {
+
+QSize ScaledSizeProvider::scaledSize(const QSize &size)
+{
+	return size * scaleFactor();
+}
+
+qreal ScaledSizeProvider::scaleFactor()
+{
+	static auto scaleFactor = getScaleFactor();
+	return scaleFactor;
+}
+
+qreal ScaledSizeProvider::getScaleFactor()
+{
+#if defined(__linux__)
+	if(isGnomeEnvironment()) {
+		auto screen = QApplication::primaryScreen();
+		auto logicalDotsPerInch = (int) screen->logicalDotsPerInch();
+		auto physicalDotsPerInch = (int) screen->physicalDotsPerInch();
+		return (qreal)logicalDotsPerInch / (qreal)physicalDotsPerInch;
+	}
+#endif
+
+	return 1;
+}
+
+#if defined(__linux__)
+bool ScaledSizeProvider::isGnomeEnvironment()
+{
+	auto currentDesktop = QString(qgetenv("XDG_CURRENT_DESKTOP"));
+	return currentDesktop.contains(QLatin1String("gnome"), Qt::CaseInsensitive)
+		   || currentDesktop.contains(QLatin1String("unity"), Qt::CaseInsensitive);
+}
+#endif
+
+} // namespace kColorPicker
\ No newline at end of file
diff --git a/src/buttons/AbstractPopupMenuButton.h b/src/common/ScaledSizeProvider.h
similarity index 58%
copy from src/buttons/AbstractPopupMenuButton.h
copy to src/common/ScaledSizeProvider.h
index 5a2b81b..1a9b655 100644
--- a/src/buttons/AbstractPopupMenuButton.h
+++ b/src/common/ScaledSizeProvider.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Damir Porobic <damir.porobic at gmx.com>
+ * Copyright (C) 2021 Damir Porobic <damir.porobic at gmx.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -17,33 +17,35 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef KCOLORPICKER_ABSTRACTPOPUPMENUBUTTON_H
-#define KCOLORPICKER_ABSTRACTPOPUPMENUBUTTON_H
+#ifndef KCOLORPICKER_SCALEDSIZEPROVIDER_H
+#define KCOLORPICKER_SCALEDSIZEPROVIDER_H
 
-#include <QToolButton>
-#include <QPainter>
-#include <QPaintEvent>
-#include <QStyleOption>
+#include <QSize>
+
+#if defined(__linux__)
+#include <QApplication>
+#include <QScreen>
+#endif
 
 namespace kColorPicker {
 
-class AbstractPopupMenuButton : public QToolButton
+class ScaledSizeProvider
 {
-Q_OBJECT
 public:
-	explicit AbstractPopupMenuButton(const QIcon &icon);
+	static QSize scaledSize(const QSize &size);
 
-signals:
-	void colorSelected(const QColor &color) const;
+private:
+	static qreal scaleFactor();
+	static qreal getScaleFactor();
 
-protected slots:
-	void paintEvent(QPaintEvent *event) override;
-	virtual void buttonClicked() = 0;
+#if defined(__linux__)
+	static bool isGnomeEnvironment();
+#endif
 
-private:
-	QColor mHoverColor;
+	ScaledSizeProvider() = default;
+	~ScaledSizeProvider() = default;
 };
 
 } // namespace kColorPicker
 
-#endif //KCOLORPICKER_ABSTRACTPOPUPMENUBUTTON_H
+#endif //KCOLORPICKER_SCALEDSIZEPROVIDER_H
diff --git a/tests/buttons/ColorButtonTest.h b/tests/buttons/ColorButtonTest.h
index 741a1a0..a335438 100644
--- a/tests/buttons/ColorButtonTest.h
+++ b/tests/buttons/ColorButtonTest.h
@@ -22,9 +22,11 @@
 
 #include <QtTest>
 
-#include "../../src/buttons/ColorButton.h"
+#include "src/buttons/ColorButton.h"
+#include "src/common/ScaledSizeProvider.h"
 
 using kColorPicker::ColorButton;
+using kColorPicker::ScaledSizeProvider;
 
 class ColorButtonTest : public QObject
 {



More information about the Neon-commits mailing list