This repository has been archived on 2020-09-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
libs/qad/widgets/colorbutton.h
Бычков Андрей 350240cdfc QAD_EXPORT
git-svn-id: svn://db.shs.com.ru/libs@719 a8b55f48-bf90-11e4-a774-851b48703e85
2020-02-28 10:05:11 +00:00

65 lines
1.9 KiB
C++

#ifndef COLORBUTTON_H
#define COLORBUTTON_H
#include <QPushButton>
#include <QFrame>
#include <QColorDialog>
#include <QMouseEvent>
#include <QAction>
#include <QMenu>
#include <QClipboard>
#include <QApplication>
#include "qad_export.h"
class QAD_EXPORT ColorButton: public QPushButton
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)
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();
QColor color() const {return pal.color(label->backgroundRole());}
bool useNativeDialog() const {return !options.testFlag(QColorDialog::DontUseNativeDialog);}
bool useAlphaChannel() const {return options.testFlag(QColorDialog::ShowAlphaChannel);}
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);}
private:
void mousePressEvent(QMouseEvent * e);
void mouseMoveEvent(QMouseEvent * e);
void resizeEvent(QResizeEvent * );
void dragEnterEvent(QDragEnterEvent * e);
void dropEvent(QDropEvent * e);
QFrame * label;
QWidget * back;
QPalette pal;
QPoint pp;
QMenu menu;
QColorDialog::ColorDialogOptions 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