mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 22:06:45 +00:00
Show the pop-up of ColorEditor immediately after the editor creation in tables
This commit is contained in:
parent
ed09424223
commit
cf487581f7
3 changed files with 25 additions and 4 deletions
|
@ -6,13 +6,15 @@
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
#include <QShowEvent>
|
||||||
|
|
||||||
#include "colorpickerpopup.hpp"
|
#include "colorpickerpopup.hpp"
|
||||||
|
|
||||||
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent)
|
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, bool popupOnStart)
|
||||||
: QPushButton(parent),
|
: QPushButton(parent),
|
||||||
mColor(color),
|
mColor(color),
|
||||||
mColorPicker(new ColorPickerPopup(this))
|
mColorPicker(new ColorPickerPopup(this)),
|
||||||
|
mPopupOnStart(popupOnStart)
|
||||||
{
|
{
|
||||||
setCheckable(true);
|
setCheckable(true);
|
||||||
connect(this, SIGNAL(clicked()), this, SLOT(showPicker()));
|
connect(this, SIGNAL(clicked()), this, SLOT(showPicker()));
|
||||||
|
@ -35,6 +37,17 @@ void CSVWidget::ColorEditor::paintEvent(QPaintEvent *event)
|
||||||
painter.drawRect(coloredRect);
|
painter.drawRect(coloredRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWidget::ColorEditor::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
QPushButton::showEvent(event);
|
||||||
|
if (isVisible() && mPopupOnStart)
|
||||||
|
{
|
||||||
|
setChecked(true);
|
||||||
|
showPicker();
|
||||||
|
mPopupOnStart = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QColor CSVWidget::ColorEditor::color() const
|
QColor CSVWidget::ColorEditor::color() const
|
||||||
{
|
{
|
||||||
return mColor;
|
return mColor;
|
||||||
|
|
|
@ -17,17 +17,19 @@ namespace CSVWidget
|
||||||
|
|
||||||
QColor mColor;
|
QColor mColor;
|
||||||
ColorPickerPopup *mColorPicker;
|
ColorPickerPopup *mColorPicker;
|
||||||
|
bool mPopupOnStart;
|
||||||
|
|
||||||
QPoint calculatePopupPosition();
|
QPoint calculatePopupPosition();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ColorEditor(const QColor &color, QWidget *parent = 0);
|
ColorEditor(const QColor &color, QWidget *parent = 0, bool popupOnStart = false);
|
||||||
|
|
||||||
QColor color() const;
|
QColor color() const;
|
||||||
void setColor(const QColor &color);
|
void setColor(const QColor &color);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
virtual void paintEvent(QPaintEvent *event);
|
||||||
|
virtual void showEvent(QShowEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showPicker();
|
void showPicker();
|
||||||
|
|
|
@ -172,6 +172,12 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
|
||||||
{
|
{
|
||||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||||
}
|
}
|
||||||
|
// For tables the pop-up of the color editor should appear immediately after the editor creation
|
||||||
|
// (the third parameter of ColorEditor's constructor)
|
||||||
|
else if (display == CSMWorld::ColumnBase::Display_Colour)
|
||||||
|
{
|
||||||
|
return new CSVWidget::ColorEditor(index.data().value<QColor>(), parent, true);
|
||||||
|
}
|
||||||
return createEditor (parent, option, index, display);
|
return createEditor (parent, option, index, display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue