connect(_name_widget, SIGNAL(editTextChanged(const QString&)),
this, SLOT(on_text_changed(const QString&)));
- // We want to close the popup when the Enter key was pressed.
- _name_widget->installEventFilter(this);
-
form->addRow(tr("Name"), _name_widget);
add_colour_option(parent, form);
return menu;
}
-bool Signal::eventFilter(QObject *obj, QEvent *evt)
-{
- QKeyEvent *keyEvent;
-
- (void)obj;
-
- if (evt->type() == QEvent::KeyPress) {
- keyEvent = static_cast<QKeyEvent*>(evt);
- if (keyEvent->key() == Qt::Key_Enter ||
- keyEvent->key() == Qt::Key_Return) {
- close_popup();
- return true;
- }
- }
-
- return false;
-}
-
void Signal::delete_pressed()
{
on_disable();
void delete_pressed();
- bool eventFilter(QObject *obj, QEvent *evt);
-
private Q_SLOTS:
void on_disable();
label_size.width(), label_size.height());
}
-bool Trace::eventFilter(QObject *obj, QEvent *evt)
-{
- QKeyEvent *keyEvent;
-
- (void)obj;
-
- if (evt->type() == QEvent::KeyPress) {
- keyEvent = static_cast<QKeyEvent*>(evt);
- if (keyEvent->key() == Qt::Key_Enter ||
- keyEvent->key() == Qt::Key_Return) {
- close_popup();
- return true;
- }
- }
-
- return false;
-}
-
QColor Trace::get_text_colour() const
{
return (_colour.lightness() > 64) ? Qt::black : Qt::white;
this, SLOT(on_text_changed(const QString&)));
form->addRow(tr("Name"), name_edit);
- // We want to close the popup when the Enter key was pressed.
- name_edit->installEventFilter(this);
-
add_colour_option(parent, form);
}
-void Trace::close_popup()
-{
- _popup->close();
-}
-
void Trace::on_popup_closed()
{
_popup = NULL;
*/
QRectF get_label_rect(int right);
- bool eventFilter(QObject *obj, QEvent *evt);
-
protected:
/**
virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
- void close_popup();
-
private Q_SLOTS:
void on_text_changed(const QString &text);
#include <QtGui>
#include <QApplication>
#include <QDesktopWidget>
+#include <QLineEdit>
#include "popup.h"
}
+bool Popup::eventFilter(QObject *obj, QEvent *evt)
+{
+ QKeyEvent *keyEvent;
+
+ (void)obj;
+
+ if (evt->type() == QEvent::KeyPress) {
+ keyEvent = static_cast<QKeyEvent*>(evt);
+ if (keyEvent->key() == Qt::Key_Enter ||
+ keyEvent->key() == Qt::Key_Return) {
+ this->close();
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void Popup::show()
+{
+ QLineEdit* le;
+
+ QWidget::show();
+
+ // We want to close the popup when the Enter key was
+ // pressed and the first editable widget had focus.
+ if ((le = this->findChild<QLineEdit*>())) {
+
+ // For combo boxes we need to hook into the parent of
+ // the line edit (i.e. the QComboBox). For edit boxes
+ // we hook into the widget directly.
+ if (le->parent()->metaObject()->className() ==
+ this->metaObject()->className())
+ le->installEventFilter(this);
+ else
+ le->parent()->installEventFilter(this);
+ }
+}
+
bool Popup::space_for_arrow() const
{
// Check if there is room for the arrow
void set_position(const QPoint point, Position pos);
+ bool eventFilter(QObject *obj, QEvent *evt);
+
+ void show();
+
private:
bool space_for_arrow() const;