コード例 #1
0
void SpinBox::setReadOnly(bool ro)
{
	if ((int)ro != (int)mReadOnly)
	{
		mReadOnly = ro;
		lineEdit()->setReadOnly(ro);
		if (ro)
			setShiftStepping(false, mCurrentButton);
	}
}
コード例 #2
0
void SpinBox::setReadOnly(bool ro)
{
	if ((int)ro != (int)mReadOnly)
	{
		mReadOnly = ro;
		editor()->setReadOnly(ro);
		if (ro)
			setShiftStepping(false);
	}
}
コード例 #3
0
void SpinBox::wheelEvent(QWheelEvent* e)
{
	if (mReadOnly)
		return;   // discard the event
	bool shift = (e->modifiers() & (Qt::ShiftModifier | Qt::AltModifier)) == Qt::ShiftModifier;
	if (setShiftStepping(shift, (e->delta() > 0 ? UP : DOWN)))
	{
		e->accept();
		return;     // hide the event from the spin widget
	}
	QSpinBox::wheelEvent(e);
}
コード例 #4
0
bool SpinBox::clickEvent(QMouseEvent* e)
{
	if (e->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(e->pos());
		if (mCurrentButton == NO_BUTTON)
		{
			e->accept();
			return true;
		}
		bool shift = (e->modifiers() & (Qt::ShiftModifier | Qt::AltModifier)) == Qt::ShiftModifier;
		if (setShiftStepping(shift, mCurrentButton))
		{
			e->accept();
			return true;     // hide the event from the spin widget
		}
	}
	return false;
}
コード例 #5
0
void SpinBox::mouseMoveEvent(QMouseEvent* e)
{
	if (e->buttons() & Qt::LeftButton)
	{
		// The left button is down. Track which spin button it's in.
		if (mReadOnly)
			return;   // discard the event
		int newButton = whichButton(e->pos());
		if (newButton != mCurrentButton)
		{
			// The mouse has moved to a new spin button.
			// Set normal or shift stepping as appropriate.
			mCurrentButton = newButton;
			bool shift = (e->modifiers() & (Qt::ShiftModifier | Qt::AltModifier)) == Qt::ShiftModifier;
			if (setShiftStepping(shift, mCurrentButton))
			{
				e->accept();
				return;     // hide the event from the spin widget
			}
		}
	}
	QSpinBox::mouseMoveEvent(e);
}
コード例 #6
0
bool SpinBox::keyEvent(QKeyEvent* e)
{
	int key   = e->key();
	int state = e->modifiers();
	if ((QApplication::mouseButtons() & 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
		bool shift = (state & (Qt::ShiftModifier | Qt::AltModifier)) == Qt::ShiftModifier;
		if ((!shift && mShiftMouse)  ||  (shift && !mShiftMouse))
		{
			// The effective shift state has changed.
			// Set normal or shift stepping as appropriate.
			if (setShiftStepping(shift, mCurrentButton))
			{
				e->accept();
				return true;     // hide the event from the spin widget
			}
		}
	}
	return false;
}
コード例 #7
0
void SpinBox::mouseReleaseEvent(QMouseEvent* e)
{
	if (e->button() == Qt::LeftButton  &&  mShiftMouse)
		setShiftStepping(false, mCurrentButton);    // cancel shift stepping
	QSpinBox::mouseReleaseEvent(e);
}
コード例 #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);
}