Skip to content

Commit

Permalink
Be nice and inform QComboBox when the popup closes.
Browse files Browse the repository at this point in the history
  • Loading branch information
KrissN committed Jun 13, 2010
1 parent d6eee21 commit db3b283
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/kcolorcombo2.cpp
Expand Up @@ -34,6 +34,7 @@
#include <QKeyEvent>
#include <QEvent>
#include <QDragEnterEvent>
#include <QDebug>
#include <klocale.h>
#include <kcolordialog.h>
#include <qclipboard.h>
Expand Down Expand Up @@ -198,6 +199,7 @@ void KColorPopup::validate()
{
hide();
close();
emit closed();

if (m_selectedRow != m_selector->rowCount()) // A normal row:
m_selector->setColor(m_selector->colorAt(m_selectedColumn, m_selectedRow));
Expand All @@ -217,6 +219,7 @@ void KColorPopup::mousePressEvent(QMouseEvent *event)
if (x < 0 || y < 0 || x >= width() || y >= height()) {
hide();
close();
emit closed();
} else
validate();

Expand Down Expand Up @@ -354,6 +357,7 @@ void KColorCombo2::init()

m_popup = new KColorPopup(this);
m_popup->installEventFilter(this);
connect(m_popup, SIGNAL(closed()), SLOT(popupClosed()));

// By default, the array is filled with setRainbowPreset().
// But we allocate it on demand (the later as possible) to avoid performances issues if the developer set another array.
Expand Down Expand Up @@ -785,4 +789,10 @@ void KColorCombo2::virtual_hook(int /*id*/, void */*data*/)
/* KBASE::virtual_hook(id, data); */
}

void KColorCombo2::popupClosed()
{
hidePopup();
}


#endif // USE_OLD_KCOLORCOMBO
5 changes: 4 additions & 1 deletion src/kcolorcombo2.h
Expand Up @@ -134,7 +134,8 @@ public slots:
* @see defaultColor() to get it.
*/
void setDefaultColor(const QColor &color);

private slots:
void popupClosed();
signals:
/**
* Emitted when the color of the widget is changed, either with setColor() or via user selection.
Expand Down Expand Up @@ -355,6 +356,8 @@ class KColorPopup : public QWidget
KColorPopup(KColorCombo2 *parent);
~KColorPopup();
void relayout(); // updateGeometry() ??
signals:
void closed();
protected:
void paintEvent(QPaintEvent */*event*/);
void mouseMoveEvent(QMouseEvent *event);
Expand Down

0 comments on commit db3b283

Please sign in to comment.