refactoring qad widgets part 1
c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
This commit is contained in:
@@ -20,15 +20,11 @@
|
||||
#ifndef COLORBUTTON_H
|
||||
#define COLORBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QFrame>
|
||||
#include <QColorDialog>
|
||||
#include <QMouseEvent>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
#include "qad_widgets_export.h"
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
class QFrame;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT ColorButton: public QPushButton
|
||||
@@ -38,48 +34,46 @@ class QAD_WIDGETS_EXPORT ColorButton: public QPushButton
|
||||
Q_PROPERTY(bool useNativeDialog READ useNativeDialog WRITE setUseNativeDialog)
|
||||
Q_PROPERTY(bool useAlphaChannel READ useAlphaChannel WRITE setUseAlphaChannel)
|
||||
Q_PROPERTY(bool frameOnly READ frameOnly WRITE setFrameOnly)
|
||||
|
||||
public:
|
||||
explicit ColorButton(QWidget * parent = 0);
|
||||
~ColorButton();
|
||||
explicit ColorButton(QWidget * parent = nullptr);
|
||||
~ColorButton() override;
|
||||
|
||||
QColor color() const {return pal.color(label->backgroundRole());}
|
||||
bool useNativeDialog() const {return !options.testFlag(QColorDialog::DontUseNativeDialog);}
|
||||
bool useAlphaChannel() const {return options.testFlag(QColorDialog::ShowAlphaChannel);}
|
||||
QColor color() const;
|
||||
bool useNativeDialog() const;
|
||||
bool useAlphaChannel() const;
|
||||
bool frameOnly() const {return frame;}
|
||||
|
||||
public slots:
|
||||
void setColor(const QColor & col);
|
||||
void setUseNativeDialog(bool yes) {if (yes) options &= ~QColorDialog::DontUseNativeDialog; else options |= QColorDialog::DontUseNativeDialog;}
|
||||
void setUseAlphaChannel(bool yes) {if (yes) options |= QColorDialog::ShowAlphaChannel; else options &= ~QColorDialog::ShowAlphaChannel;}
|
||||
void setFrameOnly(bool yes) {frame = yes; setFlat(frame); resizeEvent(0);}
|
||||
void setUseNativeDialog(bool yes);
|
||||
void setUseAlphaChannel(bool yes);
|
||||
void setFrameOnly(bool yes);
|
||||
|
||||
private slots:
|
||||
void clicked();
|
||||
void copy();
|
||||
void paste();
|
||||
void mix();
|
||||
|
||||
signals:
|
||||
void colorChanged(QColor);
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
void resizeEvent(QResizeEvent * );
|
||||
void dragEnterEvent(QDragEnterEvent * e);
|
||||
void dropEvent(QDropEvent * e);
|
||||
void changeEvent(QEvent *e);
|
||||
void mousePressEvent(QMouseEvent * e) override;
|
||||
void mouseMoveEvent(QMouseEvent * e) override;
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
void dragEnterEvent(QDragEnterEvent * e) override;
|
||||
void dropEvent(QDropEvent * e) override;
|
||||
void changeEvent(QEvent *e) override;
|
||||
|
||||
QFrame * label;
|
||||
QWidget * back;
|
||||
QAction * a_copy, * a_paste, * a_mix;
|
||||
QPalette pal;
|
||||
QPoint pp;
|
||||
QMenu menu;
|
||||
QColorDialog::ColorDialogOptions options;
|
||||
QMenu * menu;
|
||||
int options;
|
||||
bool frame;
|
||||
|
||||
private slots:
|
||||
void clicked();
|
||||
void copy() {QApplication::clipboard()->setText(color().name());}
|
||||
void paste() {QColor c(QApplication::clipboard()->text()); if (c.isValid()) setColor(c);}
|
||||
void mix();
|
||||
|
||||
signals:
|
||||
void colorChanged(QColor);
|
||||
|
||||
};
|
||||
|
||||
#endif // COLORBUTTON_H
|
||||
|
||||
Reference in New Issue
Block a user