Пример #1
0
void SpinBox::focusOutEvent(QFocusEvent* e)
{
	if (mEdited)
	{
		interpretText();
		mEdited = false;
	}
	QSpinBox::focusOutEvent(e);
}
Пример #2
0
void BigNumDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    auto spin = qobject_cast<BigNumSpin*>(editor);
    spin->interpretText();
    if (spin->cleanText().isEmpty())
        model->setData(index, QVariant(), Qt::EditRole);
    else
        model->setData(index, spin->value(), Qt::EditRole);
}
Пример #3
0
void DateEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    auto dateEdit = static_cast<QDateEdit*>(editor);

    dateEdit->interpretText();

    auto date = dateEdit->date();

    model->setData(index, date, Qt::EditRole);
}
Пример #4
0
void NumberBoxWidget::keyPressEvent ( QKeyEvent * event )
{
  if( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return )
  {
    interpretText();
    Q_EMIT( editingFinished() );
  }
  else
    QDoubleSpinBox::keyPressEvent( event );
}
Пример #5
0
DoubleSpinBox::DoubleSpinBox(const char format, QWidget *parent)
    : QAbstractSpinBox(parent), d_format(format), d_min_val(-DBL_MAX),
      d_max_val(DBL_MAX), d_value(0.0), d_step(0.1), d_prec(14) {
  if (format == 'f')
    d_prec = 1;

  setFocusPolicy(Qt::StrongFocus);
  lineEdit()->setText(locale().toString(d_value, d_format, d_prec));
  setWrapping(false);
  connect(this, SIGNAL(editingFinished()), this, SLOT(interpretText()));
}
DoubleSpinBox::DoubleSpinBox(const char format, QWidget * parent)
    :QAbstractSpinBox(parent),
     d_format(format),
     d_min_val(-DBL_MAX),
     d_max_val(DBL_MAX),
     d_value(0.0),
     d_step(0.1),
     d_prec(1)
{
    lineEdit()->setText(locale().toString(d_value, d_format, d_prec));
    setKeyboardTracking(false);
    setWrapping(false);
    connect(this, SIGNAL(editingFinished()), this, SLOT(interpretText()));
}
Пример #7
0
double DoubleSpinBox::value() {
  const bool notify(false);
  interpretText(notify);
  return d_value;
}
Пример #8
0
/******************************************************************************
* Receives events destined for the spin widget or for the edit field.
*/
bool SpinBox::eventFilter(QObject* obj, QEvent* e)
{
	if (obj == editor())
	{
		if (e->type() == QEvent::KeyPress)
		{
			// Up and down arrow keys step the value
			QKeyEvent* ke = (QKeyEvent*)e;
			int key = ke->key();
			if (key == Qt::Key_Up  ||  key == Qt::Key_Down)
			{
				if (mReadOnly)
					return true;    // discard up/down arrow keys
				int step;
				if ((ke->state() & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton)
				{
					// Shift stepping
					int val = value();
					if (key == Qt::Key_Up)
						step = mLineShiftStep - val % mLineShiftStep;
					else
						step = - ((val + mLineShiftStep - 1) % mLineShiftStep + 1);
				}
				else
					step = (key == Qt::Key_Up) ? mLineStep : -mLineStep;
				addValue(step, false);
				return true;
			}
		}
#if KDE_IS_VERSION(3,1,90)
		else if (e->type() == QEvent::Leave)
		{
			if (mEdited)
				interpretText();
		}
#endif
	}
	else
	{
		int etype = e->type();    // avoid switch compile warnings
		switch (etype)
		{
			case QEvent::MouseButtonPress:
			case QEvent::MouseButtonDblClick:
			{
				QMouseEvent* me = (QMouseEvent*)e;
				if (me->button() == Qt::LeftButton)
				{
					// It's a left button press. Set normal or shift stepping as appropriate.
					if (mReadOnly)
						return true;   // discard the event
					mCurrentButton = whichButton(me->pos());
					if (mCurrentButton == NO_BUTTON)
						return true;
					bool shift = (me->state() & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton;
					if (setShiftStepping(shift))
						return true;     // hide the event from the spin widget
					return false;    // forward event to the destination widget
				}
				break;
			}
			case QEvent::MouseButtonRelease:
			{
				QMouseEvent* me = (QMouseEvent*)e;
				if (me->button() == Qt::LeftButton  &&  mShiftMouse)
				{
					setShiftStepping(false);    // cancel shift stepping
					return false;    // forward event to the destination widget
				}
				break;
			}
			case QEvent::MouseMove:
			{
				QMouseEvent* me = (QMouseEvent*)e;
				if (me->state() & Qt::LeftButton)
				{
					// The left button is down. Track which spin button it's in.
					if (mReadOnly)
						return true;   // discard the event
					int newButton = whichButton(me->pos());
					if (newButton != mCurrentButton)
					{
						// The mouse has moved to a new spin button.
						// Set normal or shift stepping as appropriate.
						mCurrentButton = newButton;
						bool shift = (me->state() & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton;
						if (setShiftStepping(shift))
							return true;     // hide the event from the spin widget
					}
					return false;    // forward event to the destination widget
				}
				break;
			}
			case QEvent::KeyPress:
			case QEvent::KeyRelease:
			case QEvent::AccelOverride:      // this is needed to receive Shift presses!
			{
				QKeyEvent* ke = (QKeyEvent*)e;
				int key   = ke->key();
				int state = ke->state();
				if ((state & Qt::LeftButton)
				&&  (key == Qt::Key_Shift  ||  key == Qt::Key_Alt))
				{
					// The left mouse button is down, and the Shift or Alt key has changed
					if (mReadOnly)
						return true;   // discard the event
					state ^= (key == Qt::Key_Shift) ? Qt::ShiftButton : Qt::AltButton;    // new state
					bool shift = (state & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton;
					if (!shift && mShiftMouse  ||  shift && !mShiftMouse)
					{
						// The effective shift state has changed.
						// Set normal or shift stepping as appropriate.
						if (setShiftStepping(shift))
							return true;     // hide the event from the spin widget
					}
				}
				break;
			}
		}
	}
	return QSpinBox::eventFilter(obj, e);
}