mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:53:50 +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 <QPainter>
|
||||
#include <QRect>
|
||||
#include <QShowEvent>
|
||||
|
||||
#include "colorpickerpopup.hpp"
|
||||
|
||||
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent)
|
||||
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, bool popupOnStart)
|
||||
: QPushButton(parent),
|
||||
mColor(color),
|
||||
mColorPicker(new ColorPickerPopup(this))
|
||||
mColorPicker(new ColorPickerPopup(this)),
|
||||
mPopupOnStart(popupOnStart)
|
||||
{
|
||||
setCheckable(true);
|
||||
connect(this, SIGNAL(clicked()), this, SLOT(showPicker()));
|
||||
|
@ -35,6 +37,17 @@ void CSVWidget::ColorEditor::paintEvent(QPaintEvent *event)
|
|||
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
|
||||
{
|
||||
return mColor;
|
||||
|
|
|
@ -17,17 +17,19 @@ namespace CSVWidget
|
|||
|
||||
QColor mColor;
|
||||
ColorPickerPopup *mColorPicker;
|
||||
bool mPopupOnStart;
|
||||
|
||||
QPoint calculatePopupPosition();
|
||||
|
||||
public:
|
||||
ColorEditor(const QColor &color, QWidget *parent = 0);
|
||||
ColorEditor(const QColor &color, QWidget *parent = 0, bool popupOnStart = false);
|
||||
|
||||
QColor color() const;
|
||||
void setColor(const QColor &color);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
|
||||
private slots:
|
||||
void showPicker();
|
||||
|
|
|
@ -172,6 +172,12 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue