void tvalue2json(rapidjson::Value & output, const QVariant & input, rapidjson::Value::AllocatorType & allocator) { switch(input.type()) { case QVariant::Invalid: { output.SetNull(); break; } case QVariant::Bool: { output.SetBool(input.toBool()); break; } case QVariant::Int: { output.SetInt64(input.toInt()); break; } case QVariant::LongLong: { output.SetInt64(input.toLongLong()); break; } case QVariant::Double: { output.SetDouble(input.toDouble()); break; } case QVariant::String: { QByteArray str = input.toString().toUtf8(); output.SetString(str.data(), str.size(), allocator); break; } case QVariant::StringList: { QStringList list = input.toStringList(); output.SetArray(); output.Reserve(list.size(), allocator); rapidjson::Value temp; for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it) { QByteArray str = it->toUtf8(); temp.SetString(str.data(), str.size(), allocator); output.PushBack(temp, allocator); } break; } case QVariant::List: { QList<QVariant> list = input.toList(); output.SetArray(); output.Reserve(list.size(), allocator); rapidjson::Value temp; for(QList<QVariant>::const_iterator it = list.begin(); it != list.end(); ++it) { tvalue2json(temp, *it, allocator); output.PushBack(temp, allocator); } break; } case QVariant::Map: { output.SetObject(); rapidjson::Value tempK, tempV; QMap<QString, QVariant> qmap = input.toMap(); for(QMap<QString, QVariant>::const_iterator it = qmap.begin(); it != qmap.end(); ++it) { tvalue2json(tempK, it.key(), allocator); tvalue2json(tempV, it.value(), allocator); output.AddMember(tempK, tempV, allocator); } break; } case QVariant::Point: { QPoint pt = input.toPoint(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::PointF: { QPointF pt = input.toPointF(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::Size: { QSize pt = input.toSize(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::SizeF: { QSizeF pt = input.toSizeF(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::Rect: { QRect pt = input.toRect(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::RectF: { QRectF pt = input.toRectF(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::Vector2D: { QVector2D pt = input.value<QVector2D>(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::Vector3D: { QVector3D pt = input.value<QVector3D>(); output.SetArray(); output.Reserve(3, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.z(), allocator); break; } case QVariant::Vector4D: { QVector4D pt = input.value<QVector4D>(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.z(), allocator); output.PushBack(pt.w(), allocator); break; } case QVariant::Color: { QColor pt = input.value<QColor>(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.red(), allocator); output.PushBack(pt.green(), allocator); output.PushBack(pt.blue(), allocator); output.PushBack(pt.alpha(), allocator); break; } default: { output.SetNull(); assert(false && "shuldn't execute to here."); } } }
/*! Recalculate the slider's geometry and layout based on the current geometry and fonts. \param update_geometry notify the layout system and call update to redraw the scale */ void QwtSlider::layoutSlider( bool update_geometry ) { int bw = 0; if ( d_data->hasTrough ) bw = d_data->borderWidth; const QSize handleSize = qwtHandleSize( d_data->handleSize, d_data->orientation, d_data->hasTrough ); QRect sliderRect = contentsRect(); /* The marker line of the handle needs to be aligned to the scale. But the marker is in the center and we need space enough to display the rest of the handle. But the scale itself usually needs margins for displaying the tick labels, that also might needs space beyond the backbone. Now it depends on what needs more margins. If it is the slider the scale gets shrunk, otherwise the slider. */ int scaleMargin = 0; if ( d_data->scalePosition != QwtSlider::NoScale ) { int d1, d2; scaleDraw()->getBorderDistHint( font(), d1, d2 ); scaleMargin = qMax( d1, d2 ) - bw; } int scaleX, scaleY, scaleLength; if ( d_data->orientation == Qt::Horizontal ) { const int handleMargin = handleSize.width() / 2 - 1; if ( scaleMargin > handleMargin ) { int off = scaleMargin - handleMargin; sliderRect.adjust( off, 0, -off, 0 ); } scaleX = sliderRect.left() + bw + handleSize.width() / 2 - 1; scaleLength = sliderRect.width() - handleSize.width(); } else { int handleMargin = handleSize.height() / 2 - 1; if ( scaleMargin > handleMargin ) { int off = scaleMargin - handleMargin; sliderRect.adjust( 0, off, 0, -off ); } scaleY = sliderRect.top() + bw + handleSize.height() / 2 - 1; scaleLength = sliderRect.height() - handleSize.height(); } scaleLength -= 2 * bw; // now align slider and scale according to the ScalePosition if ( d_data->orientation == Qt::Horizontal ) { const int h = handleSize.height() + 2 * bw; if ( d_data->scalePosition == QwtSlider::TrailingScale ) { sliderRect.setTop( sliderRect.bottom() + 1 - h ); scaleY = sliderRect.top() - d_data->spacing; } else { sliderRect.setHeight( h ); scaleY = sliderRect.bottom() + 1 + d_data->spacing; } } else // Qt::Vertical { const int w = handleSize.width() + 2 * bw; if ( d_data->scalePosition == QwtSlider::LeadingScale ) { sliderRect.setWidth( w ); scaleX = sliderRect.right() + 1 + d_data->spacing; } else { sliderRect.setLeft( sliderRect.right() + 1 - w ); scaleX = sliderRect.left() - d_data->spacing; } } d_data->sliderRect = sliderRect; scaleDraw()->move( scaleX, scaleY ); scaleDraw()->setLength( scaleLength ); if ( update_geometry ) { d_data->sizeHintCache = QSize(); // invalidate updateGeometry(); update(); } }
void BorderLayout::setGeometry(const QRect &rect) { ItemWrapper *center = 0; int eastWidth = 0; int westWidth = 0; int northHeight = 0; int southHeight = 0; int centerHeight = 0; int i; QLayout::setGeometry(rect); for (i = 0; i < list.size(); ++i) { ItemWrapper *wrapper = list.at(i); QLayoutItem *item = wrapper->item; Position position = wrapper->position; if (position == North) { item->setGeometry(QRect(rect.x(), northHeight, rect.width(), item->sizeHint().height())); northHeight += item->geometry().height() + spacing(); } else if (position == South) { item->setGeometry(QRect(item->geometry().x(), item->geometry().y(), rect.width(), item->sizeHint().height())); southHeight += item->geometry().height() + spacing(); item->setGeometry(QRect(rect.x(), rect.y() + rect.height() - southHeight + spacing(), item->geometry().width(), item->geometry().height())); } else if (position == Center) { center = wrapper; } } centerHeight = rect.height() - northHeight - southHeight; for (i = 0; i < list.size(); ++i) { ItemWrapper *wrapper = list.at(i); QLayoutItem *item = wrapper->item; Position position = wrapper->position; if (position == West) { item->setGeometry(QRect(rect.x() + westWidth, northHeight, item->sizeHint().width(), centerHeight)); westWidth += item->geometry().width() + spacing(); } else if (position == East) { item->setGeometry(QRect(item->geometry().x(), item->geometry().y(), item->sizeHint().width(), centerHeight)); eastWidth += item->geometry().width() + spacing(); item->setGeometry(QRect( rect.x() + rect.width() - eastWidth + spacing(), northHeight, item->geometry().width(), item->geometry().height())); } } if (center) center->item->setGeometry(QRect(westWidth, northHeight, rect.width() - eastWidth - westWidth, centerHeight)); }
/*! Recalculate the slider's geometry and layout based on the current rect and fonts. \param update_geometry notify the layout system and call update to redraw the scale */ void QwtSlider::layoutSlider( bool update_geometry ) { int handleThickness; if ( orientation() == Qt::Horizontal ) handleThickness = d_data->handleSize.width(); else handleThickness = d_data->handleSize.height(); int sld1 = handleThickness / 2 - 1; int sld2 = handleThickness / 2 + handleThickness % 2; if ( d_data->bgStyle & QwtSlider::Trough ) { sld1 += d_data->borderWidth; sld2 += d_data->borderWidth; } int scd = 0; if ( d_data->scalePos != QwtSlider::NoScale ) { int d1, d2; scaleDraw()->getBorderDistHint( font(), d1, d2 ); scd = qMax( d1, d2 ); } int slo = scd - sld1; if ( slo < 0 ) slo = 0; int x, y, length; QRect sliderRect; length = x = y = 0; const QRect cr = contentsRect(); if ( orientation() == Qt::Horizontal ) { int sh = d_data->handleSize.height(); if ( d_data->bgStyle & QwtSlider::Trough ) sh += 2 * d_data->borderWidth; sliderRect.setLeft( cr.left() + slo ); sliderRect.setRight( cr.right() - slo ); sliderRect.setTop( cr.top() ); sliderRect.setBottom( cr.top() + sh - 1); if ( d_data->scalePos == QwtSlider::BottomScale ) { y = sliderRect.bottom() + d_data->spacing; } else if ( d_data->scalePos == QwtSlider::TopScale ) { sliderRect.setTop( cr.bottom() - sh + 1 ); sliderRect.setBottom( cr.bottom() ); y = sliderRect.top() - d_data->spacing; } x = sliderRect.left() + sld1; length = sliderRect.width() - ( sld1 + sld2 ); } else // Qt::Vertical { int sw = d_data->handleSize.width(); if ( d_data->bgStyle & QwtSlider::Trough ) sw += 2 * d_data->borderWidth; sliderRect.setLeft( cr.right() - sw + 1 ); sliderRect.setRight( cr.right() ); sliderRect.setTop( cr.top() + slo ); sliderRect.setBottom( cr.bottom() - slo ); if ( d_data->scalePos == QwtSlider::LeftScale ) { x = sliderRect.left() - d_data->spacing; } else if ( d_data->scalePos == QwtSlider::RightScale ) { sliderRect.setLeft( cr.left() ); sliderRect.setRight( cr.left() + sw - 1); x = sliderRect.right() + d_data->spacing; } y = sliderRect.top() + sld1; length = sliderRect.height() - ( sld1 + sld2 ); } d_data->sliderRect = sliderRect; scaleDraw()->move( x, y ); scaleDraw()->setLength( length ); d_data->map.setPaintInterval( scaleDraw()->scaleMap().p1(), scaleDraw()->scaleMap().p2() ); if ( update_geometry ) { d_data->sizeHintCache = QSize(); // invalidate updateGeometry(); update(); } }
void GlanceShower::Start () { if (!TabWidget_) { qWarning () << Q_FUNC_INFO << "no tab widget set"; return; } int count = TabWidget_->count (); if (count < 2) return; QSequentialAnimationGroup *animGroup = new QSequentialAnimationGroup; int sqr = std::sqrt ((double)count); int rows = sqr; int cols = sqr; if (rows * cols < count) ++cols; if (rows * cols < count) ++rows; QRect screenGeom = QApplication::desktop ()-> screenGeometry (Core::Instance ().GetReallyMainWindow ()); int width = screenGeom.width (); int height = screenGeom.height (); int singleW = width / cols; int singleH = height / rows; int wW = singleW * 4 / 5; int wH = singleH * 4 / 5; qreal scaleFactor = 0; QSize sSize; int animLength = 500 / (sqr); QProgressDialog pg; pg.setMinimumDuration (1000); pg.setRange (0, count); for (int row = 0; row < rows; ++row) for (int column = 0; column < cols && column + row * cols < count; ++column) { int idx = column + row * cols; pg.setValue (idx); QWidget *w = TabWidget_->widget (idx); if (!sSize.isValid ()) sSize = w->size () / 2; if (sSize != w->size ()) w->resize (sSize * 2); if (!scaleFactor) scaleFactor = std::min (static_cast<qreal> (wW) / sSize.width (), static_cast<qreal> (wH) / sSize.height ()); QPixmap pixmap (sSize * 2); w->render (&pixmap); pixmap = pixmap.scaled (sSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); { QPainter p (&pixmap); QPen pen (Qt::black); pen.setWidth (2 / scaleFactor + 1); p.setPen (pen); p.drawRect (QRect (QPoint (0, 0), sSize)); } GlanceItem *item = new GlanceItem (pixmap); item->SetIndex (idx); connect (item, SIGNAL (clicked (int)), this, SLOT (handleClicked (int))); Scene_->addItem (item); item->setTransformOriginPoint (sSize.width () / 2, sSize.height () / 2); item->setScale (scaleFactor); item->SetIdealScale (scaleFactor); item->setOpacity (0); item->moveBy (column * singleW, row * singleH); QParallelAnimationGroup *pair = new QParallelAnimationGroup; QPropertyAnimation *posAnim = new QPropertyAnimation (item, "Pos"); posAnim->setDuration (animLength); posAnim->setStartValue (QPointF (0, 0)); posAnim->setEndValue (QPointF (column * singleW, row * singleH)); posAnim->setEasingCurve (QEasingCurve::OutSine); pair->addAnimation (posAnim); QPropertyAnimation *opacityAnim = new QPropertyAnimation (item, "Opacity"); opacityAnim->setDuration (animLength); opacityAnim->setStartValue (0.); opacityAnim->setEndValue (1.); pair->addAnimation (opacityAnim); animGroup->addAnimation (pair); } setScene (Scene_); setGeometry (screenGeom); animGroup->start (); show (); }
QImage QVFbView::getBuffer( const QRect &r, int &leading ) const { switch ( viewdepth ) { case 12: case 16: { static unsigned char *imgData = 0; if ( !imgData ) { int bpl = ((hdr->width*32+31)/32)*4; imgData = new unsigned char [ bpl * hdr->height ]; } QImage img( imgData, r.width(), r.height(), 32, 0, 0, QImage::IgnoreEndian ); const int rsh = viewdepth == 12 ? 12 : 11; const int gsh = viewdepth == 12 ? 7 : 5; const int bsh = viewdepth == 12 ? 1 : 0; const int rmax = viewdepth == 12 ? 15 : 31; const int gmax = viewdepth == 12 ? 15 : 63; const int bmax = viewdepth == 12 ? 15 : 31; for ( int row = 0; row < r.height(); row++ ) { QRgb *dptr = (QRgb*)img.scanLine( row ); ushort *sptr = (ushort*)(data + hdr->dataoffset + (r.y()+row)*hdr->linestep); sptr += r.x(); #ifdef QT_QWS_REVERSE_BYTE_ENDIANNESS for ( int col=0; col < r.width()/2; col++ ) { #else for ( int col=0; col < r.width(); col++ ) { #endif ushort s = *sptr++; #ifdef QT_QWS_REVERSE_BYTE_ENDIANNESS ushort s2 = *sptr++; *dptr++ = qRgb(qRed(gammatable[(s2>>rsh)&rmax]),qGreen(gammatable[(s2>>gsh)&gmax]),qBlue(gammatable[(s2>>bsh)&bmax])); #endif *dptr++ = qRgb(qRed(gammatable[(s>>rsh)&rmax]),qGreen(gammatable[(s>>gsh)&gmax]),qBlue(gammatable[(s>>bsh)&bmax])); //*dptr++ = qRgb(((s>>rsh)&rmax)*255/rmax,((s>>gsh)&gmax)*255/gmax,((s>>bsh)&bmax)*255/bmax); } } leading = 0; return img; } case 4: { static unsigned char *imgData = 0; if ( !imgData ) { int bpl = ((hdr->width*8+31)/32)*4; imgData = new unsigned char [ bpl * hdr->height ]; } QImage img( imgData, r.width(), r.height(), 8, hdr->clut, 16, QImage::IgnoreEndian ); for ( int row = 0; row < r.height(); row++ ) { unsigned char *dptr = img.scanLine( row ); unsigned char *sptr = data + hdr->dataoffset + (r.y()+row)*hdr->linestep; sptr += r.x()/2; int col = 0; #ifdef QT_QWS_EXPERIMENTAL_REVERSE_BIT_ENDIANNESS if ( r.x() & 1 ) { *dptr++ = *sptr++ & 0x0f; col++; } for ( ; col < r.width()-1; col+=2 ) { unsigned char s = *sptr++; *dptr++ = s >> 4; *dptr++ = s & 0x0f; } if ( !(r.right() & 1) ) *dptr = *sptr >> 4; #else if ( r.x() & 1 ) { *dptr++ = *sptr++ >> 4; col++; } for ( ; col < r.width()-1; col+=2 ) { unsigned char s = *sptr++; *dptr++ = s & 0x0f; *dptr++ = s >> 4; } if ( !(r.right() & 1) ) *dptr = *sptr & 0x0f; #endif } leading = 0; return img; } case 32: { leading = r.x(); return QImage( data + hdr->dataoffset + r.y() * hdr->linestep, hdr->width, r.height(), hdr->depth, 0, 0, QImage::LittleEndian ); } case 8: { leading = r.x(); return QImage( data + hdr->dataoffset + r.y() * hdr->linestep, hdr->width, r.height(), hdr->depth, hdr->clut, 256, QImage::LittleEndian ); } case 1: { leading = r.x(); return QImage( data + hdr->dataoffset + r.y() * hdr->linestep, hdr->width, r.height(), hdr->depth, hdr->clut, #ifndef QT_QWS_EXPERIMENTAL_REVERSE_BIT_ENDIANNESS 0, QImage::LittleEndian ); #else 0, QImage::BigEndian ); #endif } } return QImage(); }
void FramelessWindow::checkBorderDragging(QMouseEvent *event) { if (isMaximized()) { return; } QPoint globalMousePos = event->globalPos(); if (m_bMousePressed) { // available geometry excludes taskbar QRect availGeometry = QApplication::desktop()->availableGeometry(); int h = availGeometry.height(); int w = availGeometry.width(); if (QApplication::desktop()->isVirtualDesktop()) { QSize sz = QApplication::desktop()->size(); h = sz.height(); w = sz.width(); } // top right corner if (m_bDragTop && m_bDragRight) { int diff = globalMousePos.x() - (m_StartGeometry.x() + m_StartGeometry.width()); int neww = m_StartGeometry.width() + diff; diff = globalMousePos.y() - m_StartGeometry.y(); int newy = m_StartGeometry.y() + diff; if (neww > 0 && newy > 0 && newy < h - 50) { QRect newg = m_StartGeometry; newg.setWidth(neww); newg.setX(m_StartGeometry.x()); newg.setY(newy); setGeometry(newg); } } // top left corner else if (m_bDragTop && m_bDragLeft) { int diff = globalMousePos.y() - m_StartGeometry.y(); int newy = m_StartGeometry.y() + diff; diff = globalMousePos.x() - m_StartGeometry.x(); int newx = m_StartGeometry.x() + diff; if (newy > 0 && newx > 0) { QRect newg = m_StartGeometry; newg.setY(newy); newg.setX(newx); setGeometry(newg); } } // bottom right corner else if (m_bDragBottom && m_bDragLeft) { int diff = globalMousePos.y() - (m_StartGeometry.y() + m_StartGeometry.height()); int newh = m_StartGeometry.height() + diff; diff = globalMousePos.x() - m_StartGeometry.x(); int newx = m_StartGeometry.x() + diff; if (newh > 0 && newx > 0) { QRect newg = m_StartGeometry; newg.setX(newx); newg.setHeight(newh); setGeometry(newg); } } else if (m_bDragTop) { int diff = globalMousePos.y() - m_StartGeometry.y(); int newy = m_StartGeometry.y() + diff; if (newy > 0 && newy < h - 50) { QRect newg = m_StartGeometry; newg.setY(newy); setGeometry(newg); } } else if (m_bDragLeft) { int diff = globalMousePos.x() - m_StartGeometry.x(); int newx = m_StartGeometry.x() + diff; if (newx > 0 && newx < w - 50) { QRect newg = m_StartGeometry; newg.setX(newx); setGeometry(newg); } } else if (m_bDragRight) { int diff = globalMousePos.x() - (m_StartGeometry.x() + m_StartGeometry.width()); int neww = m_StartGeometry.width() + diff; if (neww > 0) { QRect newg = m_StartGeometry; newg.setWidth(neww); newg.setX(m_StartGeometry.x()); setGeometry(newg); } } else if (m_bDragBottom) { int diff = globalMousePos.y() - (m_StartGeometry.y() + m_StartGeometry.height()); int newh = m_StartGeometry.height() + diff; if (newh > 0) { QRect newg = m_StartGeometry; newg.setHeight(newh); newg.setY(m_StartGeometry.y()); setGeometry(newg); } } } else { // no mouse pressed if (leftBorderHit(globalMousePos) && topBorderHit(globalMousePos)) { setCursor(Qt::SizeFDiagCursor); } else if (rightBorderHit(globalMousePos) && topBorderHit(globalMousePos)) { setCursor(Qt::SizeBDiagCursor); } else if (leftBorderHit(globalMousePos) && bottomBorderHit(globalMousePos)) { setCursor(Qt::SizeBDiagCursor); } else { if (topBorderHit(globalMousePos)) { setCursor(Qt::SizeVerCursor); } else if (leftBorderHit(globalMousePos)) { setCursor(Qt::SizeHorCursor); } else if (rightBorderHit(globalMousePos)) { setCursor(Qt::SizeHorCursor); } else if (bottomBorderHit(globalMousePos)) { setCursor(Qt::SizeVerCursor); } else { m_bDragTop = false; m_bDragLeft = false; m_bDragRight = false; m_bDragBottom = false; setCursor(Qt::ArrowCursor); } } } }
void orReport::setBackgroundRect(const QRect & r) { setBackgroundRect(r.x(), r.y(), r.width(), r.height()); }
QRect QtopiaPrintEngine::pageRect() const { QRect r = paperRect(); if (d_func()->fullPage) return r; // would be nice to get better margins than this. return QRect(d_func()->resolution/3, d_func()->resolution/3, r.width()-2*d_func()->resolution/3, r.height()-2*d_func()->resolution/3); }
XSettingsWindow::XSettingsWindow(const qutim_sdk_0_3::SettingsItemList& settings, QObject* controller, QWidget *parent) : QMainWindow(parent), p(new XSettingsWindowPrivate) { setAttribute(Qt::WA_DeleteOnClose); p->controller = controller; setWindowModality(controller ? Qt::WindowModal : Qt::NonModal); //setup ui QWidget *widget = new QWidget(this); QVBoxLayout *l = new QVBoxLayout(widget); Config cfg; cfg.beginGroup("xsettings/window"); QByteArray data; p->parent = qobject_cast<XSettingsWindow*>(qApp->activeWindow()); if(p->parent) { QRect geom = p->parent->geometry(); int width = geom.width()/15; int height = geom.height()/15; geom.adjust(width,height,-width,-height); setGeometry(geom); } else { data = cfg.value("geometry", QByteArray()); if (data.isEmpty() || !restoreGeometry(data)) { QSize desktopSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size(); resize(desktopSize.width() / 2, desktopSize.height() * 2 / 3); centerizeWidget(this); } } //init widgets p->splitter = new QSplitter(Qt::Horizontal,widget); p->listWidget = new QListWidget(widget); p->stackedWidget = new QStackedWidget(widget); //default widget QWidget *empty = new QWidget(this); p->stackedWidget->addWidget(empty); p->splitter->addWidget(p->listWidget); p->splitter->addWidget(p->stackedWidget); data = cfg.value("splitterState", QByteArray()); if (data.isEmpty() || !p->splitter->restoreState(data)) p->splitter->setSizes(QList<int>() << 80 << 250); l->addWidget(p->splitter); QDialogButtonBox::StandardButtons buttons; if (controller) buttons = QDialogButtonBox::Ok; else buttons = QDialogButtonBox::Save | QDialogButtonBox::Cancel; p->buttonBox = new QDialogButtonBox(buttons, Qt::Horizontal, widget); l->addWidget(p->buttonBox); p->buttonBox->setVisible(controller); //init actiontoolbar setCentralWidget(widget); setUnifiedTitleAndToolBarOnMac(true); p->toolBar = new ActionToolBar(widget); addToolBar(Qt::TopToolBarArea,p->toolBar); int width = style()->pixelMetric(QStyle::PM_IconViewIconSize); QSize size = QSize(width, width); p->toolBar->setIconSize(size); p->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); p->toolBar->setObjectName(QLatin1String("SettingsBar")); p->toolBar->setMovable(false); #if defined (Q_OS_WIN32) || defined(Q_OS_MAC) width = 22; #else width = style()->pixelMetric(QStyle::PM_ToolBarIconSize); #endif size = QSize(width, width); p->listWidget->setIconSize(size); p->group = new QActionGroup(widget); p->group->setExclusive(true); //connections connect(p->group,SIGNAL(triggered(QAction*)), SLOT(onGroupActionTriggered(QAction*))); connect(p->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(onCurrentItemChanged(QListWidgetItem*)) ); connect(p->buttonBox,SIGNAL(accepted()), SLOT(save())); connect(p->buttonBox,SIGNAL(rejected()), SLOT(cancel())); loadSettings(settings); if (p->group->actions().count()) p->group->actions().first()->trigger(); }
AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstStart) : QMessageBox(parent), m_settings(settings), m_disque(NULL), m_disqueTimer(NULL), m_rotateNext(false), m_disqueDelay(_I64_MAX) { const QString versionStr = QString().sprintf ( "Version %d.%02d %s, Build %d [%s], %s %s, Qt v%s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(), lamexp_version_compiler(), lamexp_version_arch(), qVersion() ); const QString copyrightStr = QString().sprintf ( "Copyright (C) 2004-%04d LoRd_MuldeR <[email protected]>. Some rights reserved.", qMax(lamexp_version_date().year(), QDate::currentDate().year()) ); for(int i = 0; i < 4; i++) { m_cartoon[i] = NULL; } QString aboutText; aboutText += QString("<h2>%1</h2>").arg(NOBR(tr("LameXP - Audio Encoder Front-end"))); aboutText += QString("<b>%1</b><br>").arg(NOBR(copyrightStr)); aboutText += QString("<b>%1</b><br><br>").arg(NOBR(versionStr)); aboutText += QString("%1<br>").arg(NOBR(tr("Please visit %1 for news and updates!").arg(LINK(lamexp_website_url())))); if(LAMEXP_DEBUG) { int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0); aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(QString("!!! --- DEBUG BUILD --- Expires at: %1 · Days left: %2 --- DEBUG BUILD --- !!!").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft)))); } else if(lamexp_version_demo()) { int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0); aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(tr("Note: This demo (pre-release) version of LameXP will expire at %1. Still %2 days left.").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft)))); } aboutText += "<hr><br>"; aboutText += "<nobr><tt>This program is free software; you can redistribute it and/or<br>"; aboutText += "modify it under the terms of the GNU General Public License<br>"; aboutText += "as published by the Free Software Foundation; either version 2<br>"; aboutText += "of the License, or (at your option) any later version.<br><br>"; aboutText += "This program is distributed in the hope that it will be useful,<br>"; aboutText += "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>"; aboutText += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>"; aboutText += "GNU General Public License for more details.<br><br>"; aboutText += "You should have received a copy of the GNU General Public License<br>"; aboutText += "along with this program; if not, write to the Free Software<br>"; aboutText += "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110−1301, USA.</tt></nobr><br>"; aboutText += "<hr><table><tr>"; aboutText += "<td valign=\"middle\"><img src=\":/icons/error_big.png\"</td><td> </td>"; aboutText += QString("<td><font color=\"darkred\">%1</font></td>").arg(tr("Note: LameXP is free software. Do <b>not</b> pay money to obtain or use LameXP! If some third-party website tries to make you pay for downloading LameXP, you should <b>not</b> respond to the offer !!!")); aboutText += "</tr></table><hr><br>"; aboutText += QString("%1<br>").arg(NOBR(tr("Special thanks go out to \"John33\" from %1 for his continuous support.")).arg(LINK("http://www.rarewares.org/"))); setText(aboutText); setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64))); setWindowTitle(tr("About LameXP")); if(firstStart) { QPushButton *firstButton = addButton(tr("Show License Text"), QMessageBox::AcceptRole); firstButton->setIcon(QIcon(":/icons/script.png")); firstButton->setIconSize(QSize(16, 16)); firstButton->setMinimumWidth(135); firstButton->disconnect(); connect(firstButton, SIGNAL(clicked()), this, SLOT(openLicenseText())); QPushButton *secondButton = addButton(tr("Accept License"), QMessageBox::AcceptRole); secondButton->setIcon(QIcon(":/icons/accept.png")); secondButton->setIconSize(QSize(16, 16)); secondButton->setMinimumWidth(120); QPushButton *thirdButton = addButton(tr("Decline License"), QMessageBox::AcceptRole); thirdButton->setIcon(QIcon(":/icons/delete.png")); thirdButton->setIconSize(QSize(16, 16)); thirdButton->setMinimumWidth(120); thirdButton->setEnabled(false); } else { QPushButton *firstButton = addButton(tr("3rd Party S/W"), QMessageBox::AcceptRole); firstButton->setIcon(QIcon(":/icons/page_white_cplusplus.png")); firstButton->setIconSize(QSize(16, 16)); firstButton->setMinimumWidth(120); firstButton->disconnect(); connect(firstButton, SIGNAL(clicked()), this, SLOT(showMoreAbout())); QPushButton *secondButton = addButton(tr("Contributors"), QMessageBox::AcceptRole); secondButton->setIcon(QIcon(":icons/user_suit.png")); secondButton->setIconSize(QSize(16, 16)); secondButton->setMinimumWidth(120); secondButton->disconnect(); connect(secondButton, SIGNAL(clicked()), this, SLOT(showAboutContributors())); QPushButton *thirdButton = addButton(tr("About Qt4"), QMessageBox::AcceptRole); thirdButton->setIcon(QIcon(":/images/Qt.svg")); thirdButton->setIconSize(QSize(16, 16)); thirdButton->setMinimumWidth(120); thirdButton->disconnect(); connect(thirdButton, SIGNAL(clicked()), this, SLOT(showAboutQt())); QPushButton *fourthButton = addButton(tr("Discard"), QMessageBox::AcceptRole); fourthButton->setIcon(QIcon(":/icons/cross.png")); fourthButton->setIconSize(QSize(16, 16)); fourthButton->setMinimumWidth(90); QPixmap disque(":/images/Disque.png"); QRect screenGeometry = QApplication::desktop()->availableGeometry(); m_disque = new QLabel(this, Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); m_disque->installEventFilter(this); m_disque->setStyleSheet("background:transparent;"); m_disque->setAttribute(Qt::WA_TranslucentBackground); m_disque->setGeometry(qrand() % (screenGeometry.width() - disque.width()), qrand() % (screenGeometry.height() - disque.height()), disque.width(), disque.height()); m_disque->setPixmap(disque); m_disque->setWindowOpacity(0.01); m_disque->show(); m_disqueFlags[0] = (qrand() > (RAND_MAX/2)); m_disqueFlags[1] = (qrand() > (RAND_MAX/2)); m_disqueTimer = new QTimer; connect(m_disqueTimer, SIGNAL(timeout()), this, SLOT(moveDisque())); m_disqueTimer->setInterval(10); m_disqueTimer->start(); } m_firstShow = firstStart; }
void QX11WindowSurface::setGeometry(const QRect &rect) { QWindowSurface::setGeometry(rect); const QSize size = rect.size(); if (d_ptr->device.size() == size || size.width() <= 0 || size.height() <= 0) return; #ifndef QT_NO_XRENDER if (d_ptr->translucentBackground) { QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen()); QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); data->xinfo = d_ptr->widget->x11Info(); data->resize(size.width(), size.height()); d_ptr->device = QPixmap(data); } else #endif { QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen()); QX11PixmapData *oldData = static_cast<QX11PixmapData *>(d_ptr->device.pixmapData()); if (oldData && !(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) { // Copy the content of the old pixmap into the new one. QX11PixmapData *newData = new QX11PixmapData(QPixmapData::PixmapType); newData->resize(size.width(), size.height()); Q_ASSERT(oldData->d == newData->d); QRegion staticRegion(staticContents()); // Make sure we're inside the boundaries of the old pixmap. staticRegion &= QRect(0, 0, oldData->w, oldData->h); const QRect boundingRect(staticRegion.boundingRect()); const int dx = boundingRect.x(); const int dy = boundingRect.y(); int num; XRectangle *rects = (XRectangle *)qt_getClipRects(staticRegion, num); GC tmpGc = XCreateGC(X11->display, oldData->hd, 0, 0); XSetClipRectangles(X11->display, tmpGc, 0, 0, rects, num, YXBanded); XCopyArea(X11->display, oldData->hd, newData->hd, tmpGc, dx, dy, qMin(boundingRect.width(), size.width()), qMin(boundingRect.height(), size.height()), dx, dy); XFreeGC(X11->display, tmpGc); newData->flags &= ~QX11PixmapData::Uninitialized; d_ptr->device = QPixmap(newData); } else { d_ptr->device = QPixmap(size); } } if (gc) { XFreeGC(X11->display, gc); gc = 0; } if (!d_ptr->device.isNull()) { gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); XSetGraphicsExposures(X11->display, gc, False); } }
void RoutingToolTip::maybeTip(const QPoint &p) { RoutingDrawWidget *drawWidget = (RoutingDrawWidget *)parentWidget(); RoutingWidget *parent = (RoutingWidget *)drawWidget->parentWidget(); StrGlobal *structure = parent->getStructure(); if (!structure) return; int i, j; // find object under cursor int xp = p.x(); int yp = p.y(); drawWidget->viewportToContents(xp, yp, xp, yp); xp = parent->deZoomVal(xp); yp = parent->deZoomVal(yp); RSItemBaseWithType *item; for(item = structure->UsedItems.first(); item; item = structure->UsedItems.next()) { if (item->containsPoint(xp, yp)) { int ix; int iy; int iw; int ih; QString tipText = ""; StrInput *in = NULL; StrOutput *out = NULL; StrFX *fx = NULL; StrPatch *patch = NULL; ix = item->x(); iy = item->y(); iw = item->width(); ih = item->height(); RSItemIO *pio = NULL; switch(item->type()) { case RSItemBaseWithType::In: in = (StrInput *)item; tipText = QString("Input: %1\nName: %2").arg(in->num()).arg(in->name()); break; case RSItemBaseWithType::Out: out = (StrOutput *)item; tipText = QString("Output: %1\nName: %2").arg(out->num()).arg(out->name()); break; case RSItemBaseWithType::FX: fx = (StrFX *)item; tipText = QString("FX: %1\nName: %2").arg(fx->num()).arg(fx->name()); break; case RSItemBaseWithType::Patch: patch = (StrPatch *)item; pio = patch->getIOAtPoint(xp, yp); if (pio) { if (pio->isOutput()) tipText = QString("Patch output: %1\nOutput name: %2\n\n").arg(pio->getIdx()).arg(pio->getDesc()); else tipText = QString("Patch input: %1\nInput name: %2\n\n").arg(pio->getIdx()).arg(pio->getDesc()); QRect r; patch->getIORect(pio->isOutput(), pio->getIdx(), r); ix = r.x(); iy = r.y(); iw = r.width(); ih = r.height(); } else { // create region without ios QRegion reg(ix, iy, iw, ih); QRect ior; for (j = 0; j < 2; j++) { for (i = 0; i < patch->getMaxIOIdx(j); i++) { patch->getIORect(j, i, ior); reg = reg.subtract(QRegion(ior)); } } // find rect with point QMemArray<QRect> rects = reg.rects(); for (i = 0; i < (int)rects.count(); i++) { if (rects[i].contains(xp, yp)) { ix = rects[i].x(); iy = rects[i].y(); iw = rects[i].width(); ih = rects[i].height(); break; } } } tipText = tipText + QString("Patch: %1\nOrder: %2\nName: %3").arg(patch->num()).arg(patch->order()).arg(patch->name()); break; default: break; } if (tipText != "") { ix = parent->zoomVal(ix); iy = parent->zoomVal(iy); iw = parent->zoomVal(iw); ih = parent->zoomVal(ih); drawWidget->contentsToViewport(ix, iy, ix, iy); tip(QRect(ix, iy, iw, ih), tipText); } } } }
void HistogramItem::drawBar(QPainter *painter, Qt::Orientation, const QRect& rect) const { painter->save(); const QColor color(painter->pen().color()); #if QT_VERSION >= 0x040000 const QRect r = rect.normalized(); #else const QRect r = rect.normalize(); #endif const int factor = 125; const QColor light(color.light(factor)); const QColor dark(color.dark(factor)); painter->setBrush(color); painter->setPen(Qt::NoPen); QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(light, 2)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2); #else QwtPainter::drawLine(painter, r.left(), r.top() + 2, r.right() + 1, r.top() + 2); #endif painter->setPen(QPen(dark, 2)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.left() + 1, r.bottom(), r.right() + 1, r.bottom()); #else QwtPainter::drawLine(painter, r.left(), r.bottom(), r.right() + 1, r.bottom()); #endif painter->setPen(QPen(light, 1)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.left(), r.top() + 1, r.left(), r.bottom()); QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1); #else QwtPainter::drawLine(painter, r.left(), r.top() + 1, r.left(), r.bottom() + 1); QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.left() + 1, r.bottom()); #endif painter->setPen(QPen(dark, 1)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.right() + 1, r.top() + 1, r.right() + 1, r.bottom()); QwtPainter::drawLine(painter, r.right(), r.top() + 2, r.right(), r.bottom() - 1); #else QwtPainter::drawLine(painter, r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() + 1); QwtPainter::drawLine(painter, r.right(), r.top() + 2, r.right(), r.bottom()); #endif painter->restore(); }
void CUniCaptureThread::run() { emit setIsRunning( true ); init(); delayTime = 10; // initial delay time frameCounter = 0; frameTimer.start(); while( !*stopThread ) { if ( *readyToProcess == true ) { // Check resolution changes QRect screenGeometry = scr->geometry(); int nScreenWidth = screenGeometry.width(); int nScreenHeight = screenGeometry.height(); if ( nScreenWidth != ScreenWidth || nScreenHeight != ScreenHeight ) { ScreenWidth = nScreenWidth; ScreenHeight = nScreenHeight; cleanupBuffers(); initBuffers(); } // Creating and filling regions data CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ), settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) ); // Horizontals // Top for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) { QImage im = scr->grabWindow( desktopID, x * regions->hWidth, 0, regions->hWidth, regions->hHeight ).toImage(); unsigned char * bufH_tmp = new unsigned char[ bufHSize ]; memcpy( bufH_tmp, im.bits(), bufHSize ); regions->regionHTop.push_back( bufH_tmp ); } // Bottom for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) { QImage im = scr->grabWindow( desktopID, x * regions->hWidth, ScreenHeight - regions->hHeight, regions->hWidth, regions->hHeight ).toImage(); unsigned char * bufH_tmp = new unsigned char[ bufHSize ]; memcpy( bufH_tmp, im.bits(), bufHSize ); regions->regionHBottom.push_back( bufH_tmp ); } // Verticals // Left for ( int x = 0; x < settings->LEDnumV; x++ ) { QImage im = scr->grabWindow( desktopID, 0, x * regions->vHeight, regions->vWidth, regions->vHeight ).toImage(); unsigned char * bufV_tmp = new unsigned char[ bufVSize ]; memcpy( bufV_tmp, im.bits(), bufVSize ); regions->regionVLeft.push_back( bufV_tmp ); } // Right for ( int x = 0; x < settings->LEDnumV; x++ ) { QImage im = scr->grabWindow( desktopID, ScreenWidth - regions->vWidth, x * regions->vHeight, regions->vWidth, regions->vHeight ).toImage(); unsigned char * bufV_tmp = new unsigned char[ bufVSize ]; memcpy( bufV_tmp, im.bits(), bufVSize ); regions->regionVRight.push_back( bufV_tmp ); } *readyToProcess = false; emit onImageCaptured( regions ); ++frameCounter; updateDelayTime(); } usleep( delayTime ); } cleanup(); emit setIsRunning( false ); //*stopThread = true; }
void TrayIcon::slotSetUnread(int unread) { m_unread = unread; this->setToolTip( m_defaultIcon.name(), i18n("Akregator"), i18np( "1 unread article", "%1 unread articles", unread ) ); if (unread <= 0 || !Settings::enableTrayIconUnreadArticleCount()) { setIconByName( m_defaultIcon.name() ); } else { // adapted from KMSystemTray::updateCount() int oldWidth = KIconLoader::SizeSmallMedium; QString countStr = QString::number( unread ); QFont f = KGlobalSettings::generalFont(); f.setBold(true); float pointSize = f.pointSizeF(); QFontMetrics fm(f); int w = fm.width(countStr); if( w > (oldWidth - 2) ) { pointSize *= float(oldWidth - 2) / float(w); f.setPointSizeF(pointSize); } // overlay QPixmap overlayImg( oldWidth, oldWidth ); overlayImg.fill( Qt::transparent ); QPainter p(&overlayImg); p.setFont(f); KColorScheme scheme(QPalette::Active, KColorScheme::View); fm = QFontMetrics(f); QRect boundingRect = fm.tightBoundingRect(countStr); boundingRect.adjust(0, 0, 0, 2); boundingRect.setHeight(qMin(boundingRect.height(), oldWidth)); boundingRect.moveTo((oldWidth - boundingRect.width()) / 2, ((oldWidth - boundingRect.height()) / 2) - 1); p.setOpacity(0.7); p.setBrush(scheme.background(KColorScheme::LinkBackground)); p.setPen(scheme.background(KColorScheme::LinkBackground).color()); p.drawRoundedRect(boundingRect, 2.0, 2.0); p.setBrush(Qt::NoBrush); p.setPen(scheme.foreground(KColorScheme::LinkText).color()); p.setOpacity(1.0); p.drawText(overlayImg.rect(), Qt::AlignCenter, countStr); p.end(); QPixmap iconPixmap = m_defaultIcon.pixmap( oldWidth, oldWidth ); QPainter pp( &iconPixmap ); pp.drawPixmap( 0, 0, overlayImg ); pp.end(); setIconByPixmap( iconPixmap ); } }
void KisCurveMagnetic::calculateCurve(KisCurve::iterator p1, KisCurve::iterator p2, KisCurve::iterator it) { if (p1 == m_curve.end() || p2 == m_curve.end()) // It happens sometimes, for example on the first click return; if (m_parent->editingMode()) return; QPoint start = (*p1).point().toPoint(); QPoint end = (*p2).point().toPoint(); QRect rc = QRect(start, end).normalize(); rc.setTopLeft(rc.topLeft() + QPoint(-8, -8)); // Enlarge the view, so problems with gaussian blur can be removed rc.setBottomRight(rc.bottomRight() + QPoint(8, 8)); // and we are able to find paths that go beyond the rect. KisPaintDeviceSP src = m_parent->currentNode()->paintDevice(); GrayMatrix dst = GrayMatrix(rc.width(), GrayCol(rc.height())); detectEdges(rc, src, dst); reduceMatrix(rc, dst, 3, 3, 3, 3); Node startNode, endNode; multiset<Node> openSet; NodeMatrix openMatrix = NodeMatrix(rc.width(), NodeCol(rc.height())); NodeMatrix closedMatrix = NodeMatrix(rc.width(), NodeCol(rc.height())); QPoint tl(rc.topLeft().x(), rc.topLeft().y()); start -= tl; // Relative to the matrix end -= tl; // Relative to the matrix findEdge(start.x(), start.y(), dst, startNode); openMatrix[startNode.col()][startNode.row()] = *openSet.insert(startNode); endNode.setPos(end); while (!openSet.empty()) { Node current = *openSet.begin(); openSet.erase(openSet.begin()); openMatrix[current.col()][current.row()].clear(); QList<Node> successors = current.getNeighbor(dst, endNode); for (QList<Node>::iterator i = successors.begin(); i != successors.end(); i++) { int col = (*i).col(); int row = (*i).row(); if ((*i) == endNode) { while (current.parent() != QPoint(-1, -1)) { it = addPoint(it, tl + current.pos(), false, false, LINEHINT); current = closedMatrix[current.parent().x()][current.parent().y()]; } return; } Node *openNode = &openMatrix[col][row]; if (*openNode != QPoint(-1, -1)) { if (*i > *openNode) continue; else { openSet.erase(qFind(openSet.begin(), openSet.end(), *openNode)); openNode->clear(); // Clear the Node } } Node *closedNode = &closedMatrix[col][row]; if (*closedNode != QPoint(-1, -1)) { if ((*i) > (*closedNode)) continue; else { openMatrix[col][row] = *openSet.insert(*closedNode); closedNode->clear(); // Clear the Node continue; } } openMatrix[col][row] = *openSet.insert(*i); } closedMatrix[current.col()][current.row()] = current; } }
void RToolMatrixItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { const QAbstractItemModel* model = index.model(); Q_ASSERT(model); if (!model->parent(index).isValid()) { // bool hidden = model->data(index, Qt::UserRole+2).toBool(); // qDebug() << "hidden: " << hidden; // if (hidden) { // return; // } // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; #ifdef Q_OS_MAC buttonOption.state |= QStyle::State_Raised; #endif buttonOption.state &= ~QStyle::State_HasFocus; buttonOption.rect = option.rect; buttonOption.palette = option.palette; buttonOption.features = QStyleOptionButton::None; painter->save(); QColor buttonColor(230, 230, 230); QBrush buttonBrush = option.palette.button(); if (!buttonBrush.gradient() && buttonBrush.texture().isNull()) { buttonColor = buttonBrush.color(); } QColor outlineColor = buttonColor.darker(150); QColor highlightColor = buttonColor.lighter(130); // Only draw topline if the previous item is expanded QModelIndex previousIndex = model->index(index.row() - 1, index.column()); bool drawTopline = (index.row() > 0 && treeView->isExpanded(previousIndex)); int highlightOffset = drawTopline ? 1 : 0; QLinearGradient gradient(option.rect.topLeft(), option.rect.bottomLeft()); gradient.setColorAt(0, buttonColor.lighter(102)); gradient.setColorAt(1, buttonColor.darker(106)); painter->setPen(Qt::NoPen); painter->setBrush(gradient); painter->drawRect(option.rect); painter->setPen(highlightColor); painter->drawLine(option.rect.topLeft() + QPoint(0, highlightOffset), option.rect.topRight() + QPoint(0, highlightOffset)); painter->setPen(outlineColor); if (drawTopline) { painter->drawLine(option.rect.topLeft(), option.rect.topRight()); } painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); painter->restore(); QStyleOption branchOption; static const int i = 9; QRect r = option.rect; branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); branchOption.palette = option.palette; branchOption.state = QStyle::State_Children; if (treeView->isExpanded(index)) { branchOption.state |= QStyle::State_Open; } treeView->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, treeView); // draw text QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height()); QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, model->data(index, Qt::DisplayRole).toString()); treeView->style()->drawItemText(painter, textrect, Qt::AlignCenter, option.palette, treeView->isEnabled(), text); } else { QItemDelegate::paint(painter, option, index); } }
OSDPretty::OSDPretty(Mode mode, QWidget* parent) : QWidget(parent), ui_(new Ui_OSDPretty), mode_(mode), background_color_(kPresetBlue), background_opacity_(0.85), popup_display_(0), font_(QFont()), disable_duration_(false), timeout_(new QTimer(this)), fading_enabled_(false), fader_(new QTimeLine(300, this)), toggle_mode_(false) { Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint; setWindowFlags(flags); setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_X11NetWmWindowTypeNotification, true); setAttribute(Qt::WA_ShowWithoutActivating, true); ui_->setupUi(this); #ifdef Q_OS_WIN32 // Don't show the window in the taskbar. Qt::ToolTip does this too, but it // adds an extra ugly shadow. int ex_style = GetWindowLong(winId(), GWL_EXSTYLE); ex_style |= WS_EX_NOACTIVATE; SetWindowLong(winId(), GWL_EXSTYLE, ex_style); #endif // Mode settings switch (mode_) { case Mode_Popup: setCursor(QCursor(Qt::ArrowCursor)); break; case Mode_Draggable: setCursor(QCursor(Qt::OpenHandCursor)); break; } // Timeout timeout_->setSingleShot(true); timeout_->setInterval(5000); connect(timeout_, SIGNAL(timeout()), SLOT(hide())); ui_->icon->setMaximumSize(kMaxIconSize, kMaxIconSize); // Fader connect(fader_, SIGNAL(valueChanged(qreal)), SLOT(FaderValueChanged(qreal))); connect(fader_, SIGNAL(finished()), SLOT(FaderFinished())); #ifdef Q_OS_WIN32 set_fading_enabled(true); #endif // Load the show edges and corners QImage shadow_edge(":osd_shadow_edge.png"); QImage shadow_corner(":osd_shadow_corner.png"); for (int i = 0; i < 4; ++i) { QTransform rotation = QTransform().rotate(90 * i); shadow_edge_[i] = QPixmap::fromImage(shadow_edge.transformed(rotation)); shadow_corner_[i] = QPixmap::fromImage(shadow_corner.transformed(rotation)); } background_ = QPixmap(":osd_background.png"); // Set the margins to allow for the drop shadow QBoxLayout* l = static_cast<QBoxLayout*>(layout()); int margin = l->margin() + kDropShadowSize; l->setMargin(margin); // Get current screen resolution QRect screenResolution = QApplication::desktop()->screenGeometry(); // Leave 200 px for icon ui_->summary->setMaximumWidth(screenResolution.width() - 200); ui_->message->setMaximumWidth(screenResolution.width() - 200); // Set maximum size for the OSD, a little margin here too setMaximumSize(screenResolution.width() - 100, screenResolution.height() - 100); // Don't load settings here, they will be reloaded anyway on creation }
Rectangle::Rectangle(QRect coord,PaintingContext * pc) : Figure(pc) { vertexs_=new QRect(coord.x(),coord.y(),coord.width(),coord.height()); }
Size getSystemResolution() { QDesktopWidget desk; QRect systemRes = desk.screenGeometry(); return Size(systemRes.width(), systemRes.height()); }
void QzTools::centerWidgetOnScreen(QWidget* w) { const QRect screen = QApplication::desktop()->screenGeometry(); const QRect size = w->geometry(); w->move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2); }
ribi::QtFunctionPlotterMainDialog::QtFunctionPlotterMainDialog(QWidget *parent) : QtHideAndShowDialog(parent), ui(new Ui::QtFunctionPlotterMainDialog), m_curve(new QwtPlotCurve), m_plot(new QwtPlot) { #ifndef NDEBUG Test(); #endif ui->setupUi(this); //Create plot { assert(!ui->plot_contents->layout()); QGridLayout * const layout = new QGridLayout; ui->plot_contents->setLayout(layout); layout->addWidget(m_plot); #ifdef _WIN32 m_plot->setCanvasBackground(QBrush(QColor(255,255,255))); #else m_plot->setCanvasBackground(QColor(255,255,255)); #endif m_curve->attach(m_plot); m_curve->setStyle(QwtPlotCurve::Lines); m_curve->setPen(QPen(QColor(128,128,128))); } QObject::connect( this->ui->edit_equation, &QLineEdit::textChanged, this, &ribi::QtFunctionPlotterMainDialog::OnAnyChange ); QObject::connect( this->ui->box_minx, SIGNAL(valueChanged(QString)), this, SLOT(OnAnyChange()) ); QObject::connect( this->ui->box_maxx, SIGNAL(valueChanged(QString)), this, SLOT(OnAnyChange()) ); ui->box_minx->setValue(-1.0); ui->box_maxx->setValue(1.0); ui->edit_equation->setText("cos(x)"); { //Put the dialog in the screen center at 50% x 50% of its size const QRect screen = QApplication::desktop()->screenGeometry(); this->setGeometry(0,0,screen.width() / 2,screen.height() /2 ); this->move( screen.center() - this->rect().center() ); } }
void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option) { // From windowsstyle but modified to enable AA if (option->rect.width() <= 1 || option->rect.height() <= 1) return; QRect r = option->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; QString pixmapName; pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld", "$qt_ia", uint(option->state), element, size, option->palette.cacheKey()); if (!QPixmapCache::find(pixmapName, pixmap)) { int border = size/5; int sqsize = 2*(size/2); QImage image(sqsize, sqsize, QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter imagePainter(&image); imagePainter.setRenderHint(QPainter::Antialiasing, true); imagePainter.translate(0.5, 0.5); QPolygon a; switch (element) { case QStyle::PE_IndicatorArrowUp: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); break; case QStyle::PE_IndicatorArrowDown: a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); break; case QStyle::PE_IndicatorArrowRight: a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; case QStyle::PE_IndicatorArrowLeft: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; default: break; } int bsx = 0; int bsy = 0; if (option->state & QStyle::State_Sunken) { bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical); } QRect bounds = a.boundingRect(); int sx = sqsize / 2 - bounds.center().x() - 1; int sy = sqsize / 2 - bounds.center().y() - 1; imagePainter.translate(sx + bsx, sy + bsy); if (!(option->state & QStyle::State_Enabled)) { QColor foreGround(150, 150, 150, 150); imagePainter.setBrush(option->palette.mid().color()); imagePainter.setPen(option->palette.mid().color()); } else { QColor shadow(0, 0, 0, 100); imagePainter.translate(0, 1); imagePainter.setPen(shadow); imagePainter.setBrush(shadow); QColor foreGround(255, 255, 255, 210); imagePainter.drawPolygon(a); imagePainter.translate(0, -1); imagePainter.setPen(foreGround); imagePainter.setBrush(foreGround); } imagePainter.drawPolygon(a); imagePainter.end(); pixmap = QPixmap::fromImage(image); QPixmapCache::insert(pixmapName, pixmap); } int xOffset = r.x() + (r.width() - size)/2; int yOffset = r.y() + (r.height() - size)/2; painter->drawPixmap(xOffset, yOffset, pixmap); }
void KisWaveletNoiseReduction::processImpl(KisPaintDeviceSP device, const QRect& applyRect, const KisFilterConfigurationSP _config, KoUpdater* progressUpdater ) const { Q_ASSERT(device); // TODO take selections into account float threshold; KisFilterConfigurationSP config = _config ? _config : defaultConfiguration(device); threshold = config->getDouble("threshold", BEST_WAVELET_THRESHOLD_VALUE); qint32 depth = device->colorSpace()->colorChannelCount(); int size; int maxrectsize = qMax(applyRect.width(), applyRect.height()); for (size = 2; size < maxrectsize; size *= 2) ; KisMathToolbox mathToolbox; if (progressUpdater) { progressUpdater->setRange(0, mathToolbox.fastWaveletTotalSteps(applyRect) * 2 + size*size*depth); } int count = 0; // dbgFilters << size <<"" << maxrectsize <<"" << srcTopLeft.x() <<"" << srcTopLeft.y(); // dbgFilters <<"Transforming..."; KisMathToolbox::KisWavelet* buff = 0; KisMathToolbox::KisWavelet* wav = 0; try { buff = mathToolbox.initWavelet(device, applyRect); } catch (std::bad_alloc) { if (buff) delete buff; return; } try { wav = mathToolbox.fastWaveletTransformation(device, applyRect, buff); } catch (std::bad_alloc) { if (wav) delete wav; return; } // dbgFilters <<"Thresholding..."; float* fin = wav->coeffs + wav->depth * wav->size * wav->size; for (float* it = wav->coeffs + wav->depth; it < fin; it++) { if (*it > threshold) { *it -= threshold; } else if (*it < -threshold) { *it += threshold; } else { *it = 0.; } if (progressUpdater) progressUpdater->setValue(++count); } // dbgFilters <<"Untransforming..."; mathToolbox.fastWaveletUntransformation(device, applyRect, wav, buff); delete wav; delete buff; }
// Draws a cached pixmap with shadow void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) { QPixmap cache; QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); if (!QPixmapCache::find(pixmapName, cache)) { QPixmap px = icon.pixmap(rect.size()); cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); cache.fill(Qt::transparent); QPainter cachePainter(&cache); if (iconMode == QIcon::Disabled) { QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); for (int y=0; y<im.height(); ++y) { QRgb *scanLine = (QRgb*)im.scanLine(y); for (int x=0; x<im.width(); ++x) { QRgb pixel = *scanLine; char intensity = qGray(pixel); *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel)); ++scanLine; } } px = QPixmap::fromImage(im); } // Draw shadow QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied); tmp.fill(Qt::transparent); QPainter tmpPainter(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); tmpPainter.drawPixmap(QPoint(radius, radius), px); tmpPainter.end(); // blur the alpha channel QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(Qt::transparent); QPainter blurPainter(&blurred); qt_blurImage(&blurPainter, tmp, radius, false, true); blurPainter.end(); tmp = blurred; // blacken the image... tmpPainter.begin(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); tmpPainter.fillRect(tmp.rect(), color); tmpPainter.end(); tmpPainter.begin(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); tmpPainter.fillRect(tmp.rect(), color); tmpPainter.end(); // draw the blurred drop shadow... cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp); // Draw the actual pixmap... cachePainter.drawPixmap(QPoint(radius, radius) + offset, px); QPixmapCache::insert(pixmapName, cache); } QRect targetRect = cache.rect(); targetRect.moveCenter(rect.center()); p->drawPixmap(targetRect.topLeft() - offset, cache); }
template <> const Item::Bound payloadGetBound(const Overlay::Pointer& overlay) { if (overlay->is3D()) { return static_cast<Base3DOverlay*>(overlay.get())->getBounds(); } else { QRect bounds = static_cast<Overlay2D*>(overlay.get())->getBounds(); return AABox(glm::vec3(bounds.x(), bounds.y(), 0.0f), glm::vec3(bounds.width(), bounds.height(), 0.1f)); } }
IntRect::IntRect(const QRect& r) : m_location(r.topLeft()) , m_size(r.width(), r.height()) { }
void CameraView::newMouseData(struct MouseData mouseData) { QRect selectionBox; // Set ROI if(mouseData.leftButtonRelease) { int roiX = mouseData.selectionBox.x(); int roiY = mouseData.selectionBox.y(); int roiW = mouseData.selectionBox.width(); int roiH = mouseData.selectionBox.height(); int frameW = ui->frameLabel->width(); int frameH = ui->frameLabel->height(); // Copy box dimensions from mouseData to taskData if(roiW < 0) { roiX = roiX + roiW; roiW = roiW*-1; } if(roiH < 0) { roiY = roiY + roiH; roiH = roiH*-1; } selectionBox.setX(roiX-(frameW-capW)/2); selectionBox.setY(roiY-(frameH-capH)/2); selectionBox.setWidth(roiW); selectionBox.setHeight(roiH); INFOMSG((">>> froi(%d,%d[%d,%d]) roi(%d,%d[%d,%d]) cap(%d,%d) frame(%d,%d)",selectionBox.x(),selectionBox.y(),selectionBox.width(),selectionBox.height(),roiX,roiY,roiW,roiH,capW,capH,frameW,frameH)); if(processingThread->resizeToFitWindow) { double ratioW = (double)capW/(double)frameW; double ratioH = (double)capH/(double)frameH; selectionBox.setX((double)roiX*ratioW); selectionBox.setY((double)roiY*ratioH); selectionBox.setWidth((double)roiW*ratioW); selectionBox.setHeight((double)roiH*ratioH); INFOMSG((">>> froi(%d,%d[%d,%d]) roi(%d,%d[%d,%d]) cap(%d,%d) frame(%d,%d)",selectionBox.x(),selectionBox.y(),selectionBox.width(),selectionBox.height(),roiX,roiY,roiW,roiH,capW,capH,frameW,frameH)); } if((selectionBox.x()<0)||(selectionBox.y()<0)|| ((selectionBox.x()+selectionBox.width())>capW)|| ((selectionBox.y()+selectionBox.height())>capH) || roiW <=0 || roiH <= 0) { // Display error message // QMessageBox::warning(this,"ERROR:","Selection box outside range. Please try again."); WARNMSG(("ROI out of range")); }else{ INFOMSG(("NEW ROI x,y(%d,%d) w,h(%d,%d)",selectionBox.x(),selectionBox.y(),selectionBox.width(),selectionBox.height())); emit setROI(selectionBox); } } }
static void _ZFP_ZFUISysWindowImpl_sys_Qt_updateWindowLayout(ZF_IN ZFUISysWindow *window, ZF_IN QWidget *nativeWindow) { QRect screenRect = QApplication::desktop()->screenGeometry(); ZFUIRect frame = ZFPROTOCOL_ACCESS(ZFUISysWindow)->notifyMeasureWindow(window, ZFUIRectMake(0, 0, screenRect.width(), screenRect.height())); nativeWindow->setGeometry(ZFImpl_sys_Qt_ZFUIKit_ZFUIRectToQRect(frame)); if(nativeWindow->layout() != zfnull) { QRect t(0, 0, frame.size.width, frame.size.height); for(int i = 0; i < nativeWindow->layout()->count(); ++i) { nativeWindow->layout()->itemAt(i)->widget()->setGeometry(t); } } }