mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 08:40:53 +01:00
Replacement for KColorButton
This commit is contained in:
@@ -64,7 +64,8 @@ message("GIT_COMMIT_SHA :" ${GIT_COMMIT_SHA})
|
||||
|
||||
if(BUILD_WITH_KF6 AND BUILD_KF6)
|
||||
message("KF6_GIT_TAG :" ${KF6_GIT_TAG})
|
||||
else()
|
||||
endif()
|
||||
if(NOT BUILD_WITH_KF6)
|
||||
add_definitions(-DBUILD_WITHOUT_KF6)
|
||||
endif()
|
||||
message("QET_COMPONENTS :" ${QET_COMPONENTS})
|
||||
|
||||
@@ -111,6 +111,8 @@ set(QET_SRC_FILES
|
||||
${QET_DIR}/sources/borderproperties.h
|
||||
${QET_DIR}/sources/bordertitleblock.cpp
|
||||
${QET_DIR}/sources/bordertitleblock.h
|
||||
${QET_DIR}/sources/colorbutton.cpp
|
||||
${QET_DIR}/sources/colorbutton.h
|
||||
${QET_DIR}/sources/conductorautonumerotation.cpp
|
||||
${QET_DIR}/sources/conductorautonumerotation.h
|
||||
${QET_DIR}/sources/conductornumexport.cpp
|
||||
|
||||
85
sources/colorbutton.cpp
Normal file
85
sources/colorbutton.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright 2006-2025 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "colorbutton.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QPainter>
|
||||
|
||||
/**
|
||||
@brief ColorButton::ColorButton
|
||||
Simple constructor
|
||||
@param parent QObject parent of the ColorButton
|
||||
*/
|
||||
ColorButton::ColorButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
connect(this, &QPushButton::clicked, this, &ColorButton::clicked);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Getter for current color
|
||||
@return The current selected color
|
||||
*/
|
||||
const QColor ColorButton::color()
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Setter for current color
|
||||
*/
|
||||
void ColorButton::setColor(const QColor &color)
|
||||
{
|
||||
m_color = color;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ColorButton::clicked
|
||||
Opens a color selection dialog and lets the user select a color.
|
||||
@param checked Not used
|
||||
*/
|
||||
void ColorButton::clicked(bool checked)
|
||||
{
|
||||
// Open color selection dialog
|
||||
auto newColor = QColorDialog::getColor(m_color);
|
||||
|
||||
// Validate user input
|
||||
if (newColor.isValid()) {
|
||||
m_color = newColor;
|
||||
emit changed(newColor);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ColorButton::paintEvent
|
||||
Paints a filled rectangle with the current selected color on the button surface.
|
||||
@param e Paint event context
|
||||
*/
|
||||
void ColorButton::paintEvent(QPaintEvent *e) {
|
||||
QPushButton::paintEvent(e);
|
||||
QPainter painter(this);
|
||||
|
||||
// Get dimensions of te button paint surface
|
||||
auto r_width = painter.device()->width();
|
||||
auto r_height = painter.device()->height();
|
||||
|
||||
// Paint a rectangle with a margin of 5
|
||||
auto color_indicator = QRect(5, 5, r_width - 10, r_height - 10);
|
||||
painter.fillRect(color_indicator, m_color);
|
||||
}
|
||||
53
sources/colorbutton.h
Normal file
53
sources/colorbutton.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2006-2025 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef COLORBUTTON_H
|
||||
#define COLORBUTTON_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QObject>
|
||||
#include <QPushButton>
|
||||
#include <Qt>
|
||||
|
||||
/**
|
||||
@brief The ColorButton class
|
||||
*/
|
||||
class ColorButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ColorButton(QWidget * = nullptr);
|
||||
|
||||
const QColor color();
|
||||
void setColor(const QColor &);
|
||||
|
||||
public slots:
|
||||
void clicked(bool = false);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
signals:
|
||||
void changed(const QColor &);
|
||||
|
||||
private:
|
||||
/// @brief Current selected color
|
||||
QColor m_color = Qt::black;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -140,10 +140,7 @@ void DynamicTextFieldEditor::updateForm()
|
||||
ui -> m_user_text_le -> setText(m_text_field.data() -> text());
|
||||
ui -> m_size_sb -> setValue(m_text_field.data() -> font().pointSize());
|
||||
ui->m_keep_visual_rotation_cb->setChecked(m_text_field.data()->keepVisualRotation());
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
m_color_kpb -> setColor(m_text_field.data() -> color());
|
||||
#endif
|
||||
ui -> m_width_sb -> setValue(m_text_field.data() -> textWidth());
|
||||
ui -> m_font_pb -> setText(m_text_field -> font().family());
|
||||
|
||||
@@ -169,16 +166,13 @@ void DynamicTextFieldEditor::updateForm()
|
||||
|
||||
void DynamicTextFieldEditor::setupWidget()
|
||||
{
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
m_color_kpb = new KColorButton(this);
|
||||
m_color_kpb = new ColorButton(this);
|
||||
m_color_kpb->setObjectName(QString::fromUtf8("m_color_kpb"));
|
||||
|
||||
connect(m_color_kpb, &KColorButton::changed,
|
||||
connect(m_color_kpb, &ColorButton::changed,
|
||||
this, &DynamicTextFieldEditor::on_m_color_kpb_changed);
|
||||
|
||||
ui->m_main_grid_layout->addWidget(m_color_kpb, 6, 1, 1, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::setUpConnections()
|
||||
|
||||
@@ -21,10 +21,7 @@
|
||||
#include "../elementitemeditor.h"
|
||||
#include "../graphicspart/partdynamictextfield.h"
|
||||
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
# include <KColorButton>
|
||||
#endif
|
||||
#include "../../colorbutton.h"
|
||||
|
||||
namespace Ui {
|
||||
class DynamicTextFieldEditor;
|
||||
@@ -77,10 +74,7 @@ class DynamicTextFieldEditor : public ElementItemEditor {
|
||||
QList<PartDynamicTextField*> m_parts;
|
||||
QList<QMetaObject::Connection> m_connection_list;
|
||||
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
KColorButton* m_color_kpb = nullptr;
|
||||
#endif
|
||||
ColorButton* m_color_kpb = nullptr;
|
||||
};
|
||||
|
||||
#endif // DYNAMICTEXTFIELDEDITOR_H
|
||||
|
||||
@@ -62,10 +62,7 @@ void TextEditor::updateForm()
|
||||
m_rotation_sb -> setValue(m_text -> rotation());
|
||||
m_size_sb -> setValue(m_text -> font().pointSize());
|
||||
m_font_pb -> setText(m_text -> font().family());
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
m_color_pb -> setColor(m_text -> defaultTextColor());
|
||||
#endif
|
||||
|
||||
setUpEditConnection();
|
||||
}
|
||||
@@ -344,19 +341,16 @@ void TextEditor::setUpWidget(QWidget *parent)
|
||||
m_line_edit->setPlaceholderText(tr("Entrer votre texte ici"));
|
||||
|
||||
gridLayout->addWidget(m_line_edit, 0, 0, 1, 6);
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
m_color_pb = new KColorButton(parent);
|
||||
m_color_pb = new ColorButton(parent);
|
||||
m_color_pb->setObjectName(QString::fromUtf8("m_color_pb"));
|
||||
|
||||
connect(
|
||||
m_color_pb,
|
||||
&KColorButton::changed,
|
||||
&ColorButton::changed,
|
||||
this,
|
||||
&TextEditor::on_m_color_pb_changed);
|
||||
|
||||
gridLayout->addWidget(m_color_pb, 2, 5, 1, 1);
|
||||
#endif
|
||||
QLabel *label_5 = new QLabel(parent);
|
||||
label_5->setObjectName(QString::fromUtf8("label_5"));
|
||||
|
||||
|
||||
@@ -25,10 +25,7 @@
|
||||
#include <QSpinBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
#include <KColorButton>
|
||||
#endif
|
||||
#include "../../colorbutton.h"
|
||||
class PartText;
|
||||
|
||||
class TextEditor : public ElementItemEditor {
|
||||
@@ -65,10 +62,7 @@ class TextEditor : public ElementItemEditor {
|
||||
QSpinBox *m_size_sb;
|
||||
QLineEdit *m_line_edit;
|
||||
QPushButton *m_font_pb;
|
||||
#ifdef BUILD_WITHOUT_KF6
|
||||
#else
|
||||
KColorButton *m_color_pb;
|
||||
#endif
|
||||
ColorButton *m_color_pb;
|
||||
};
|
||||
|
||||
#endif // TEXTEDITOR_H
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="KColorButton" name="m_text_color_kpb"/>
|
||||
<widget class="ColorButton" name="m_text_color_kpb"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="m_text_size_sb">
|
||||
@@ -458,7 +458,7 @@
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="1">
|
||||
<widget class="KColorButton" name="m_color_kpb"/>
|
||||
<widget class="ColorButton" name="m_color_kpb"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
@@ -530,7 +530,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="KColorButton" name="m_color_2_kpb"/>
|
||||
<widget class="ColorButton" name="m_color_2_kpb"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -576,9 +576,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KColorButton</class>
|
||||
<class>ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>kcolorbutton.h</header>
|
||||
<header>../colorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
|
||||
@@ -478,13 +478,13 @@ void ShapeGraphicsItemPropertiesWidget::setUpEditConnection()
|
||||
m_edit_connection << connect (ui->m_size_dsb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
||||
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
||||
|
||||
m_edit_connection << connect (ui->m_color_kpb, &KColorButton::changed,
|
||||
m_edit_connection << connect (ui->m_color_kpb, &ColorButton::changed,
|
||||
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
||||
|
||||
m_edit_connection << connect (ui->m_brush_style_cb, QOverload<int>::of(&QComboBox::activated),
|
||||
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
||||
|
||||
m_edit_connection << connect (ui->m_brush_color_kpb, &KColorButton::changed,
|
||||
m_edit_connection << connect (ui->m_brush_color_kpb, &ColorButton::changed,
|
||||
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
||||
|
||||
m_edit_connection << connect (ui->m_close_polygon, &QCheckBox::clicked,
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="KColorButton" name="m_color_kpb"/>
|
||||
<widget class="ColorButton" name="m_color_kpb"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="m_size_dsb">
|
||||
@@ -215,7 +215,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="KColorButton" name="m_brush_color_kpb"/>
|
||||
<widget class="ColorButton" name="m_brush_color_kpb"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -251,9 +251,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KColorButton</class>
|
||||
<class>ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>kcolorbutton.h</header>
|
||||
<header>../colorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
|
||||
Reference in New Issue
Block a user