void QgsDateTimeEdit::mousePressEvent( QMouseEvent *event ) { // catch mouse press on the button (when the current value is null) // in non-calendar mode: modifiy the date so it leads to showing current date (don't bother about time) // in calendar mode: be sure NULL is displayed when needed and show page of current date in calendar widget bool updateCalendar = false; if ( mIsNull ) { QStyle::SubControl control; if ( calendarPopup() ) { QStyleOptionComboBox optCombo; optCombo.init( this ); optCombo.editable = true; optCombo.subControls = QStyle::SC_All; control = style()->hitTestComplexControl( QStyle::CC_ComboBox, &optCombo, event->pos(), this ); if ( control == QStyle::SC_ComboBoxArrow && calendarWidget() ) { mCurrentPressEvent = true; // ensure the line edit still displays NULL updateCalendar = true; displayNull( updateCalendar ); mCurrentPressEvent = false; } } else { QStyleOptionSpinBox opt; this->initStyleOption( &opt ); control = style()->hitTestComplexControl( QStyle::CC_SpinBox, &opt, event->pos(), this ); if ( control == QStyle::SC_SpinBoxDown || control == QStyle::SC_SpinBoxUp ) { mCurrentPressEvent = true; disconnect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed ); resetBeforeChange( control == QStyle::SC_SpinBoxDown ? -1 : 1 ); connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed ); mCurrentPressEvent = false; } } } QDateTimeEdit::mousePressEvent( event ); if ( updateCalendar ) { // set calendar page to current date to avoid going to minimal date page when value is null calendarWidget()->setCurrentPage( QDate::currentDate().year(), QDate::currentDate().month() ); } }
void KoSliderComboContainer::mousePressEvent(QMouseEvent *e) { QStyleOptionComboBox opt; opt.init(m_parent); opt.subControls = QStyle::SC_All; opt.activeSubControls = QStyle::SC_ComboBoxArrow; QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, m_parent->mapFromGlobal(e->globalPos()), m_parent); if (sc == QStyle::SC_ComboBoxArrow) setAttribute(Qt::WA_NoMouseReplay); QMenu::mousePressEvent(e); }
void KoSliderCombo::paintEvent(QPaintEvent *) { QStylePainter gc(this); gc.setPen(palette().color(QPalette::Text)); QStyleOptionComboBox opt; opt.init(this); opt.subControls = QStyle::SC_All; opt.editable = true; gc.drawComplexControl(QStyle::CC_ComboBox, opt); gc.drawControl(QStyle::CE_ComboBoxLabel, opt); }
void KoSliderCombo::mousePressEvent(QMouseEvent *e) { QStyleOptionComboBox opt; opt.init(this); opt.subControls = QStyle::SC_All; opt.editable = true; QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->pos(), this); if (sc == QStyle::SC_ComboBoxArrow && !d->container->isVisible()) { d->showPopup(); } else QComboBox::mousePressEvent(e); }
QSize KoSliderCombo::minimumSizeHint() const { QSize sh; const QFontMetrics &fm = fontMetrics(); sh.setWidth(5 * fm.width(QLatin1Char('8'))); sh.setHeight(qMax(fm.lineSpacing(), 14) + 2); // add style and strut values QStyleOptionComboBox opt; opt.init(this); opt.subControls = QStyle::SC_All; opt.editable = true; sh = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, this); return sh.expandedTo(QApplication::globalStrut()); }
KoSliderCombo::KoSliderCombo(QWidget *parent) : QComboBox(parent) ,d(new KoSliderComboPrivate()) { d->thePublic = this; d->minimum = 0.0; d->maximum = 100.0; d->decimals = 2; d->container = new KoSliderComboContainer(this); d->container->setAttribute(Qt::WA_WindowPropagation); QStyleOptionComboBox opt; opt.init(this); // d->container->setFrameStyle(style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, this)); d->slider = new QSlider(Qt::Horizontal); d->slider->setMinimum(0); d->slider->setMaximum(256); d->slider->setPageStep(10); d->slider->setValue(0); // When set to true, causes flicker on Qt 4.6. Any reason to keep it? d->firstShowOfSlider = false; //true; QHBoxLayout * l = new QHBoxLayout(); l->setMargin(2); l->setSpacing(2); l->addWidget(d->slider); d->container->setLayout(l); d->container->resize(200, 30); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setEditable(true); //setEditText(KGlobal::locale()->formatNumber(0, d->decimals)); setEditText(QString::number(0.0f, 'f', d->decimals)); connect(d->slider, SIGNAL(valueChanged(int)), SLOT(sliderValueChanged(int))); connect(d->slider, SIGNAL(sliderReleased()), SLOT(sliderReleased())); connect(lineEdit(), SIGNAL(editingFinished()), SLOT(lineEditFinished())); }
void KoResourceSelector::mousePressEvent( QMouseEvent * event ) { QStyleOptionComboBox opt; opt.init( this ); opt.subControls = QStyle::SC_All; opt.activeSubControls = QStyle::SC_ComboBoxArrow; QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, mapFromGlobal(event->globalPos()), this); // only clicking on combobox arrow shows popup, // otherwise the resourceApplied signal is send with the current resource if (sc == QStyle::SC_ComboBoxArrow) QComboBox::mousePressEvent( event ); else { QModelIndex index = view()->currentIndex(); if( ! index.isValid() ) return; KoResource * resource = static_cast<KoResource*>( index.internalPointer() ); if( resource ) emit resourceApplied( resource ); } }
void KoSliderCombo::KoSliderComboPrivate::showPopup() { if(firstShowOfSlider) { container->show(); //show container a bit early so the slider can be layout'ed firstShowOfSlider = false; } QStyleOptionSlider opt; opt.init(slider); opt.maximum=256; opt.sliderPosition = opt.sliderValue = slider->value(); int hdlPos = thePublic->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle).center().x(); QStyleOptionComboBox optThis; optThis.init(thePublic); optThis.subControls = QStyle::SC_All; optThis.editable = true; int arrowPos = thePublic->style()->subControlRect(QStyle::CC_ComboBox, &optThis, QStyle::SC_ComboBoxArrow).center().x(); QSize popSize = container->size(); QRect popupRect(thePublic->mapToGlobal(QPoint(arrowPos - hdlPos - slider->x(), thePublic->size().height())), popSize); // Make sure the popup is not drawn outside the screen area QRect screenRect = QApplication::desktop()->availableGeometry(thePublic); if (popupRect.right() > screenRect.right()) popupRect.translate(screenRect.right() - popupRect.right(), 0); if (popupRect.left() < screenRect.left()) popupRect.translate(screenRect.left() - popupRect.left(), 0); if (popupRect.bottom() > screenRect.bottom()) popupRect.translate(0, -(thePublic->height() + container->height())); container->setGeometry(popupRect); container->raise(); container->show(); slider->setFocus(); }