/*! \brief Draw the button label \param painter Painter \sa The Qt Manual on QPushButton */ void QwtArrowButton::drawButtonLabel(QPainter *painter) { const bool isVertical = d_data->arrowType == Qt::UpArrow || d_data->arrowType == Qt::DownArrow; const QRect r = labelRect(); QSize boundingSize = labelRect().size(); if ( isVertical ) boundingSize.transpose(); const int w = (boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum; QSize arrow = arrowSize(Qt::RightArrow, QSize(w, boundingSize.height())); if ( isVertical ) arrow.transpose(); QRect contentsSize; // aligned rect where to paint all arrows if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow ) { contentsSize.setWidth(d_data->num * arrow.width() + (d_data->num - 1) * Spacing); contentsSize.setHeight(arrow.height()); } else { contentsSize.setWidth(arrow.width()); contentsSize.setHeight(d_data->num * arrow.height() + (d_data->num - 1) * Spacing); } QRect arrowRect(contentsSize); arrowRect.moveCenter(r.center()); arrowRect.setSize(arrow); painter->save(); for (int i = 0; i < d_data->num; i++) { drawArrow(painter, arrowRect, d_data->arrowType); int dx = 0; int dy = 0; if ( isVertical ) dy = arrow.height() + Spacing; else dx = arrow.width() + Spacing; #if QT_VERSION >= 0x040000 arrowRect.translate(dx, dy); #else arrowRect.moveBy(dx, dy); #endif } painter->restore(); if ( hasFocus() ) { #if QT_VERSION >= 0x040000 QStyleOptionFocusRect option; option.init(this); option.backgroundColor = palette().color(QPalette::Background); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, painter, this); #else const QRect focusRect = style().subRect(QStyle::SR_PushButtonFocusRect, this); style().drawPrimitive(QStyle::PE_FocusRect, painter, focusRect, colorGroup()); #endif } }
void DisplayWidget::mouseReleaseEvent(QMouseEvent *event) { QVariant v; v.setValue(selectedTile); switch(currentTool) { case t_pen: { model()->setData(this->indexAt(event->pos()), v); break; } case t_box: case t_hollow_box: case t_circle: case t_hollow_circle: { rubberBand->hide(); int headerHeight = this->horizontalHeader()->height(); int headerWidth = this->verticalHeader()->width(); // rubber band draws based on the displays 0,0 as origin // indexes use inside corner of the headers as 0,0 // // v-- this is 0,0 for rubber band // []================= // ||+<-- this is 0,0 for table fields // || QRect selection = rubberBand->geometry().adjusted(-headerWidth, -headerHeight, -headerWidth, -headerHeight); QModelIndex center = this->indexAt(selection.center()); QModelIndex topLeft = this->indexAt(selection.topLeft()); QModelIndex bottomRight = this->indexAt(selection.bottomRight()); // determine selections if(currentTool == t_box) { for(int i = topLeft.column(); i <= bottomRight.column(); i++) { for(int j = topLeft.row(); j <= bottomRight.row(); j++) { model()->setData(model()->index(j, i), v); } } } else if(currentTool == t_hollow_box) { for(int i = topLeft.column(); i <= bottomRight.column(); i++) { model()->setData(model()->index(topLeft.row(), i), v); model()->setData(model()->index(bottomRight.row(), i), v); } for(int i = topLeft.row(); i <= bottomRight.row(); i++) { model()->setData(model()->index(i, topLeft.column()), v); model()->setData(model()->index(i, bottomRight.column()), v); } } // currently suffer w/even diameters, index at center does not necessarily correlate to // center of the actual circle. adjust to use diameter / 2 for calculations. else if(currentTool == t_circle) { // x-radius double a = bottomRight.column() - center.column(); // y-radius double b = topLeft.row() - center.row(); // (x-h)^2/a^2 + (y-k)^2/b^2 <= 1 for(int i = topLeft.column(); i <= bottomRight.column(); i++) { for(int j = topLeft.row(); j <= bottomRight.row(); j++) { double topx = i - center.column(); double topy = j - center.row(); if( (((topx * topx) / (a * a)) + ((topy * topy) / (b * b))) <= 1.0 ) { model()->setData(model()->index(j, i), v); } } } } else if(currentTool == t_hollow_circle) { // x(t) = (right - center) * cos(t) = a * cos(t) // y(t) = (top - center) * sin(t) = b * sin(t) int a = bottomRight.column() - center.column(); int b = topLeft.row() - center.row(); for(double d = 0.0; d <= 2 * M_PI; d+=(M_PI / 100)) { int x = center.column() + qRound(a * cos(d)); int y = center.row() + qRound(b * sin(d)); model()->setData(model()->index(y, x), v); } } break; } default: break; } }
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { QString title = VLCModel::getMeta( index, COLUMN_TITLE ); QString duration = VLCModel::getMeta( index, COLUMN_DURATION ); if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST ); QString album = VLCModel::getMeta( index, COLUMN_ALBUM ); QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER ); QString artistAlbum = artist; if( !album.isEmpty() ) { if( !artist.isEmpty() ) artistAlbum += ": "; artistAlbum += album; if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum ); } QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) ); //Draw selection rectangle and current playing item indication paintBackground( painter, option, index ); QRect artRect( artPix.rect() ); artRect.moveCenter( QPoint( artRect.center().x() + 3, option.rect.center().y() ) ); //Draw album art painter->drawPixmap( artRect, artPix ); //Start drawing text painter->save(); if( option.state & QStyle::State_Selected ) painter->setPen( option.palette.color( QPalette::HighlightedText ) ); QTextOption textOpt( Qt::AlignVCenter | Qt::AlignLeft ); textOpt.setWrapMode( QTextOption::NoWrap ); QFont f( index.data( Qt::FontRole ).value<QFont>() ); //Draw title info f.setItalic( true ); f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) ); f.setBold( index.data( PLModel::IsCurrentRole ).toBool() ); painter->setFont( f ); QFontMetrics fm( painter->fontMetrics() ); QRect textRect = option.rect.adjusted( LISTVIEW_ART_SIZE + 10, 0, -10, 0 ); if( !artistAlbum.isEmpty() ) { textRect.setHeight( fm.height() ); textRect.moveBottom( option.rect.center().y() - 2 ); } //Draw children indicator if( !index.data( PLModel::IsLeafNodeRole ).toBool() ) { QPixmap dirPix = QPixmap( ":/type/node" ); painter->drawPixmap( QPoint( textRect.x(), textRect.center().y() - dirPix.height() / 2 ), dirPix ); textRect.setLeft( textRect.x() + dirPix.width() + 5 ); } painter->drawText( textRect, fm.elidedText( title, Qt::ElideRight, textRect.width() ), textOpt ); // Draw artist and album info if( !artistAlbum.isEmpty() ) { f.setItalic( false ); painter->setFont( f ); fm = painter->fontMetrics(); textRect.moveTop( textRect.bottom() + 4 ); textRect.setLeft( textRect.x() + 20 ); painter->drawText( textRect, fm.elidedText( artistAlbum, Qt::ElideRight, textRect.width() ), textOpt ); } painter->restore(); }
//! [3] void Window::setupShapes() { QPainterPath truck; //! [3] truck.setFillRule(Qt::WindingFill); truck.moveTo(0.0, 87.0); truck.lineTo(0.0, 60.0); truck.lineTo(10.0, 60.0); truck.lineTo(35.0, 35.0); truck.lineTo(100.0, 35.0); truck.lineTo(100.0, 87.0); truck.lineTo(0.0, 87.0); truck.moveTo(17.0, 60.0); truck.lineTo(55.0, 60.0); truck.lineTo(55.0, 40.0); truck.lineTo(37.0, 40.0); truck.lineTo(17.0, 60.0); truck.addEllipse(17.0, 75.0, 25.0, 25.0); truck.addEllipse(63.0, 75.0, 25.0, 25.0); //! [4] QPainterPath clock; //! [4] clock.addEllipse(-50.0, -50.0, 100.0, 100.0); clock.addEllipse(-48.0, -48.0, 96.0, 96.0); clock.moveTo(0.0, 0.0); clock.lineTo(-2.0, -2.0); clock.lineTo(0.0, -42.0); clock.lineTo(2.0, -2.0); clock.lineTo(0.0, 0.0); clock.moveTo(0.0, 0.0); clock.lineTo(2.732, -0.732); clock.lineTo(24.495, 14.142); clock.lineTo(0.732, 2.732); clock.lineTo(0.0, 0.0); //! [5] QPainterPath house; //! [5] house.moveTo(-45.0, -20.0); house.lineTo(0.0, -45.0); house.lineTo(45.0, -20.0); house.lineTo(45.0, 45.0); house.lineTo(-45.0, 45.0); house.lineTo(-45.0, -20.0); house.addRect(15.0, 5.0, 20.0, 35.0); house.addRect(-35.0, -15.0, 25.0, 25.0); //! [6] QPainterPath text; //! [6] QFont font; font.setPixelSize(50); QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt")); text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt")); //! [7] shapes.append(clock); shapes.append(house); shapes.append(text); shapes.append(truck); connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int))); }
void QQuickViewTestUtil::centerOnScreen(QQuickView *window, const QSize &size) { const QRect screenGeometry = window->screen()->availableGeometry(); const QPoint offset = QPoint(size.width() / 2, size.height() / 2); window->setFramePosition(screenGeometry.center() - offset); }
void tSunMoonDialog::ProcessMoonPixmap( QPixmap& moonPixmap ) { if( m_MoonData.Phase < 0.99 ) { QRect r = moonPixmap.rect(); qreal diameter = r.width() * 0.744; QRectF rF( r.center().x() - 0.5 - diameter / 2, r.center().y() + 1 - diameter / 2, diameter, diameter ); QPainterPath darkMoonPath; if( m_MoonData.Phase > 0.01 ) { QPainterPath halfMoonPath; halfMoonPath.moveTo( rF.left() + rF.width() / 2, rF.top() + rF.height() ); qreal sweep = 180; if( m_MoonData.Waxing ) { sweep *= -1; } halfMoonPath.arcTo( rF.left(), rF.top(), diameter, diameter, 90, sweep ); halfMoonPath.lineTo( rF.left() + rF.width() / 2, rF.top() ); QPainterPath cresentMoonPath; cresentMoonPath.addEllipse( rF.center(), diameter * cos( m_MoonData.Phase * M_PI ) / 2, diameter / 2 ); if( m_MoonData.Phase < 0.5 ) { darkMoonPath = halfMoonPath.united( cresentMoonPath ); } else { darkMoonPath = halfMoonPath.subtracted( cresentMoonPath ); } } else { darkMoonPath.addEllipse( rF.center(), diameter / 2, diameter / 2 ); } QPainter painter( &moonPixmap ); painter.setRenderHint( QPainter::Antialiasing ); painter.setPen( Qt::NoPen ); QColor c( 0, 0, 0, 170 ); painter.setBrush( QBrush( c ) ); painter.drawPath( darkMoonPath ); painter.end(); } // invert the image if in northern hemisphere if( m_Position.Y() >= 0 ) { QPixmap tempPixmap( moonPixmap ); moonPixmap.fill( QColor( 0, 0, 0, 0 ) ); QPainter painter( &moonPixmap ); painter.rotate( 180 ); painter.drawPixmap( QPoint( -moonPixmap.width(), -moonPixmap.height() ), tempPixmap ); painter.end(); } }
// 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("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); }
/* * Constructs a CustomFaceManagerUI as a child of 'parent', with the * name 'name' and widget flags set to 'f'. */ CustomFaceManagerUI::CustomFaceManagerUI( QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ) { QImage img; img.loadFromData( image0_data, sizeof( image0_data ), "PNG" ); image0 = img; img.loadFromData( image1_data, sizeof( image1_data ), "PNG" ); image1 = img; img.loadFromData( image2_data, sizeof( image2_data ), "PNG" ); image2 = img; if ( !name ) setName( "CustomFaceManagerUI" ); CustomFaceManagerUILayout = new QGridLayout( this, 1, 1, 3, 0, "CustomFaceManagerUILayout"); layout9 = new QVBoxLayout( 0, 0, 6, "layout9"); frame7 = new QFrame( this, "frame7" ); frame7->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, frame7->sizePolicy().hasHeightForWidth() ) ); frame7->setFrameShape( QFrame::TabWidgetPanel ); frame7->setFrameShadow( QFrame::Raised ); frame7Layout = new QGridLayout( frame7, 1, 1, 2, 0, "frame7Layout"); layout1 = new QHBoxLayout( 0, 0, 6, "layout1"); tbtnImport = new QToolButton( frame7, "tbtnImport" ); tbtnImport->setAutoRaise( TRUE ); layout1->addWidget( tbtnImport ); tbtnExport = new QToolButton( frame7, "tbtnExport" ); tbtnExport->setAutoRaise( TRUE ); layout1->addWidget( tbtnExport ); tbtnAddGroup = new QToolButton( frame7, "tbtnAddGroup" ); tbtnAddGroup->setIconSet( QIconSet( image0 ) ); tbtnAddGroup->setUsesTextLabel( TRUE ); tbtnAddGroup->setAutoRaise( TRUE ); tbtnAddGroup->setTextPosition( QToolButton::BesideIcon ); layout1->addWidget( tbtnAddGroup ); tbtnEditGroup = new QToolButton( frame7, "tbtnEditGroup" ); tbtnEditGroup->setIconSet( QIconSet( image1 ) ); tbtnEditGroup->setUsesTextLabel( TRUE ); tbtnEditGroup->setAutoRaise( TRUE ); tbtnEditGroup->setTextPosition( QToolButton::BesideIcon ); layout1->addWidget( tbtnEditGroup ); tbtnRemoveGroup = new QToolButton( frame7, "tbtnRemoveGroup" ); tbtnRemoveGroup->setIconSet( QIconSet( image2 ) ); tbtnRemoveGroup->setUsesBigPixmap( TRUE ); tbtnRemoveGroup->setUsesTextLabel( TRUE ); tbtnRemoveGroup->setAutoRaise( TRUE ); tbtnRemoveGroup->setTextPosition( QToolButton::BesideIcon ); layout1->addWidget( tbtnRemoveGroup ); frame7Layout->addLayout( layout1, 0, 0 ); layout9->addWidget( frame7 ); layout7 = new QHBoxLayout( 0, 0, 6, "layout7"); frame6 = new QFrame( this, "frame6" ); frame6->setPaletteForegroundColor( QColor( 0, 124, 206 ) ); frame6->setFrameShape( QFrame::Box ); frame6->setFrameShadow( QFrame::Plain ); frame6Layout = new QGridLayout( frame6, 1, 1, 1, 0, "frame6Layout"); lvGroups = new QListView( frame6, "lvGroups" ); lvGroups->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)7, 0, 0, lvGroups->sizePolicy().hasHeightForWidth() ) ); lvGroups->setMinimumSize( QSize( 100, 0 ) ); lvGroups->setMaximumSize( QSize( 250, 32767 ) ); lvGroups->setFrameShape( QListView::NoFrame ); lvGroups->setFrameShadow( QListView::Plain ); lvGroups->setLineWidth( 1 ); lvGroups->setHScrollBarMode( QListView::AlwaysOff ); lvGroups->setSorting( -1 ); // don't sort frame6Layout->addWidget( lvGroups, 0, 0 ); layout7->addWidget( frame6 ); frmMain = new QFrame( this, "frmMain" ); frmMain->setPaletteForegroundColor( QColor( 0, 124, 206 ) ); frmMain->setPaletteBackgroundColor( QColor( 255, 255, 255 ) ); frmMain->setFrameShape( QFrame::Box ); frmMain->setFrameShadow( QFrame::Plain ); frmMainLayout = new QGridLayout( frmMain, 1, 1, 11, 6, "frmMainLayout"); layout6 = new QHBoxLayout( 0, 0, 6, "layout6"); tblFaceList = new QTable( frmMain, "tblFaceList" ); tblFaceList->setNumCols( tblFaceList->numCols() + 1 ); tblFaceList->horizontalHeader()->setLabel( tblFaceList->numCols() - 1, i18n("No." ) ); tblFaceList->setNumCols( tblFaceList->numCols() + 1 ); tblFaceList->horizontalHeader()->setLabel( tblFaceList->numCols() - 1, i18n("Smiley" ) ); tblFaceList->setNumCols( tblFaceList->numCols() + 1 ); tblFaceList->horizontalHeader()->setLabel( tblFaceList->numCols() - 1, i18n("Shortcut" ) ); tblFaceList->setFrameShape( QTable::GroupBoxPanel ); tblFaceList->setFrameShadow( QTable::Plain ); tblFaceList->setHScrollBarMode( QTable::AlwaysOff ); tblFaceList->setNumRows( 0 ); tblFaceList->setNumCols( 3 ); tblFaceList->setSelectionMode( QTable::MultiRow ); tblFaceList->setFocusStyle( QTable::FollowStyle ); layout6->addWidget( tblFaceList ); layout5 = new QVBoxLayout( 0, 0, 6, "layout5"); btnAdd = new QPushButton( frmMain, "btnAdd" ); layout5->addWidget( btnAdd ); btnRemove = new QPushButton( frmMain, "btnRemove" ); layout5->addWidget( btnRemove ); btnEdit = new QPushButton( frmMain, "btnEdit" ); layout5->addWidget( btnEdit ); btnUp = new QPushButton( frmMain, "btnUp" ); layout5->addWidget( btnUp ); btnDown = new QPushButton( frmMain, "btnDown" ); layout5->addWidget( btnDown ); btnMoveTo = new QPushButton( frmMain, "btnMoveTo" ); layout5->addWidget( btnMoveTo ); spacer1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); layout5->addItem( spacer1 ); lblPreview = new QLabel( frmMain, "lblPreview" ); lblPreview->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, lblPreview->sizePolicy().hasHeightForWidth() ) ); lblPreview->setMinimumSize( QSize( 100, 85 ) ); lblPreview->setMaximumSize( QSize( 100, 85 ) ); lblPreview->setPaletteForegroundColor( QColor( 0, 124, 206 ) ); lblPreview->setFrameShape( QLabel::Box ); layout5->addWidget( lblPreview ); layout6->addLayout( layout5 ); frmMainLayout->addLayout( layout6, 0, 0 ); layout7->addWidget( frmMain ); layout9->addLayout( layout7 ); layout8 = new QHBoxLayout( 0, 0, 6, "layout8"); spacer2 = new QSpacerItem( 91, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout8->addItem( spacer2 ); btnOK = new QPushButton( this, "btnOK" ); layout8->addWidget( btnOK ); btnCancel = new QPushButton( this, "btnCancel" ); layout8->addWidget( btnCancel ); layout9->addLayout( layout8 ); CustomFaceManagerUILayout->addLayout( layout9, 0, 0 ); languageChange(); resize( QSize(521, 382).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); QRect scr = KApplication::desktop()->screenGeometry(); move(scr.center()-rect().center()); }
QtTreesearcherMainDialog::QtTreesearcherMainDialog(QWidget *parent) : QDialog(parent), ui(new Ui::QtTreesearcherMainDialog), m_bd_likelihood_widget{new QtBirthDeathModelLikelihoodWidget}, m_bd_max_likelihood_widget{new QtBirthDeathModelMaxLikelihoodWidget}, m_bd_parameters_widget{new QtBirthDeathModelParametersWidget}, m_ltt_image{new QLabel}, m_phylogeny{}, m_tree_image{new QLabel} { ui->setupUi(this); { assert(!this->ui->widget_center->layout()); QHBoxLayout * const my_layout{new QHBoxLayout}; ui->widget_center->setLayout(my_layout); my_layout->addWidget(m_ltt_image); my_layout->addWidget(m_tree_image); assert(this->ui->widget_center->layout()); } { assert(!ui->page_parameters_bd->layout()); QGridLayout * const my_layout{new QGridLayout}; ui->page_parameters_bd->setLayout(my_layout); my_layout->addWidget(m_bd_parameters_widget); assert(ui->page_parameters_bd->layout()); } //BD analyse { assert(!ui->page_analyse_bd->layout()); QVBoxLayout * const my_layout{new QVBoxLayout}; ui->page_analyse_bd->setLayout(my_layout); assert(ui->page_analyse_bd->layout()); my_layout->addWidget(new QLabel("Likelihood")); my_layout->addWidget(m_bd_likelihood_widget); my_layout->addWidget(new QLabel("Max likelihood")); my_layout->addWidget(m_bd_max_likelihood_widget); } QObject::connect(m_bd_parameters_widget,SIGNAL(signal_parameters_changed()),this,SLOT(OnBirthDeathParametersChanged())); //Parse some libraries { auto& r = ribi::Rinside().Get(); r.parseEvalQ("library(ape)"); r.parseEvalQ("library(geiger)"); } //Center on screen { //Put the dialog in the screen center const QRect screen = QApplication::desktop()->screenGeometry(); this->setGeometry(0,0,screen.width() * 9 / 10,screen.height() * 9 / 10); this->move( screen.center() - this->rect().center() ); } OnBirthDeathParametersChanged(); }
void RegionGrabber::paintEvent( QPaintEvent* e ) { Q_UNUSED( e ); if ( grabbing ) // grabWindow() should just get the background return; QPainter painter( this ); QPalette pal(QToolTip::palette()); QFont font = QToolTip::font(); QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight ); handleColor.setAlpha( 160 ); QColor overlayColor( 0, 0, 0, 160 ); QColor textColor = pal.color( QPalette::Active, QPalette::Text ); QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base ); painter.drawPixmap(0, 0, pixmap); painter.setFont(font); QRect r = selection; if ( !selection.isNull() ) { QRegion grey( rect() ); grey = grey.subtracted( r ); painter.setClipRegion( grey ); painter.setPen( Qt::NoPen ); painter.setBrush( overlayColor ); painter.drawRect( rect() ); painter.setClipRect( rect() ); drawRect( &painter, r, handleColor ); } if ( showHelp ) { painter.setPen( textColor ); painter.setBrush( textBackgroundColor ); QString helpText = "Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit."; helpTextRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText ); helpTextRect.adjust( -2, -2, 4, 2 ); drawRect( &painter, helpTextRect, textColor, textBackgroundColor ); painter.drawText( helpTextRect.adjusted( 3, 3, -3, -3 ), helpText ); } if ( selection.isNull() ) { return; } // The grabbed region is everything which is covered by the drawn // rectangles (border included). This means that there is no 0px // selection, since a 0px wide rectangle will always be drawn as a line. QString txt = QString( "%1x%2" ).arg( selection.width() ) .arg( selection.height() ); QRect textRect = painter.boundingRect( rect(), Qt::AlignLeft, txt ); QRect boundingRect = textRect.adjusted( -4, 0, 0, 0); if ( textRect.width() < r.width() - 2*handleSize && textRect.height() < r.height() - 2*handleSize && ( r.width() > 100 && r.height() > 100 ) ) // center, unsuitable for small selections { boundingRect.moveCenter( r.center() ); textRect.moveCenter( r.center() ); } else if ( r.y() - 3 > textRect.height() && r.x() + textRect.width() < rect().right() ) // on top, left aligned { boundingRect.moveBottomLeft( QPoint( r.x(), r.y() - 3 ) ); textRect.moveBottomLeft( QPoint( r.x() + 2, r.y() - 3 ) ); } else if ( r.x() - 3 > textRect.width() ) // left, top aligned { boundingRect.moveTopRight( QPoint( r.x() - 3, r.y() ) ); textRect.moveTopRight( QPoint( r.x() - 5, r.y() ) ); } else if ( r.bottom() + 3 + textRect.height() < rect().bottom() && r.right() > textRect.width() ) // at bottom, right aligned { boundingRect.moveTopRight( QPoint( r.right(), r.bottom() + 3 ) ); textRect.moveTopRight( QPoint( r.right() - 2, r.bottom() + 3 ) ); } else if ( r.right() + textRect.width() + 3 < rect().width() ) // right, bottom aligned { boundingRect.moveBottomLeft( QPoint( r.right() + 3, r.bottom() ) ); textRect.moveBottomLeft( QPoint( r.right() + 5, r.bottom() ) ); } // if the above didn't catch it, you are running on a very tiny screen... drawRect( &painter, boundingRect, textColor, textBackgroundColor ); painter.drawText( textRect, txt ); if ( ( r.height() > handleSize*2 && r.width() > handleSize*2 ) || !mouseDown ) { updateHandles(); painter.setPen( Qt::NoPen ); painter.setBrush( handleColor ); painter.setClipRegion( handleMask( StrokeMask ) ); painter.drawRect( rect() ); handleColor.setAlpha( 60 ); painter.setBrush( handleColor ); painter.setClipRegion( handleMask( FillMask ) ); painter.drawRect( rect() ); } }
void CustomStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { QColor borderColor; QPen oldPen(2); QPainterPath path; int x1, x2, y1, y2; switch (control) { #ifndef QT_NO_COMBOBOX case CC_ComboBox: if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); // backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole()); bool isEnabled = (comboBox->state & State_Enabled); bool focus = isEnabled && (comboBox->state & State_HasFocus); oldPen = painter->pen(); painter->setPen(Qt::black); if(!focus) borderColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6)); else borderColor = QColor(255, 255, 0); oldPen.setColor(borderColor); painter->setPen(oldPen); // painter->setBrush(Qt::transparent); painter->fillRect(option->rect, option->palette.brush(QPalette::Base)); option->rect.getCoords(&x1, &y1, &x2, &y2); path.moveTo(x1+0, y1); path.lineTo(x2-0, y1); path.lineTo(x2, y1+0); path.lineTo(x2, y2-0); path.lineTo(x2-0, y2); path.lineTo(x1+0, y2); path.lineTo(x1, y2-0); path.lineTo(x1, y1+0); path.lineTo(x1+0, y1); painter->drawPath(path); QRect downArrowRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxArrow, widget); if (comboBox->subControls & SC_ComboBoxArrow) { QStyleOptionButton buttonOption; buttonOption.QStyleOption::operator=(*comboBox); QRect arrowRect(option->rect.right() - downArrowRect.width(), option->rect.top(), downArrowRect.width(), downArrowRect.height()); buttonOption.rect = arrowRect; if(!focus) buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver); else buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus); // drawControl(CE_PushButtonBevel, &buttonOption, painter, widget); buttonOption.rect = downArrowRect; if(!focus) buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver); else buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus); // drawControl(CE_PushButtonBevel, &buttonOption, painter, widget); QImage imgLeftArrow(qt_scrollbar_button_arrow_left); QImage imgRightArrow(qt_scrollbar_button_arrow_right); //downArrow.setColor(1, comboBox->palette.foreground().color().rgba()); // int offset = comboBox->direction == Qt::RightToLeft ? -2 : 2; if(!focus) { imgRightArrow.setColor(1,qRgb(48,255,0)); imgLeftArrow.setColor(1,qRgb(48,255,0)); } else { imgRightArrow.setColor(1,qRgb(255,255,0)); imgLeftArrow.setColor(1,qRgb(255,255,0)); } painter->drawImage(downArrowRect.center().x() - imgLeftArrow.width() / 2,// + offset, downArrowRect.center().y() - imgLeftArrow.height() / 2 + 1, imgLeftArrow); painter->drawImage(arrowRect.center().x() - imgRightArrow.width() / 2,// + offset, arrowRect.center().y() - imgRightArrow.height() / 2 + 1, imgRightArrow); } QRect editFieldRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget); if (comboBox->subControls & SC_ComboBoxEditField) { // QStyleOptionButton buttonOption; // buttonOption.rect = editFieldRect; // if(!focus) // buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver); // else // buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus); // drawPrimitive(PE_FrameLineEdit, &buttonOption, painter, widget); } painter->restore(); } break; #endif // QT_NO_COMBOBOX default: QWindowsStyle::drawComplexControl(control, option, painter, widget); break; } }
void QAbstractButtonPrivate::moveFocus(int key) { QList<QAbstractButton *> buttonList = queryButtonList();; #ifndef QT_NO_BUTTONGROUP bool exclusive = group ? group->d_func()->exclusive : autoExclusive; #else bool exclusive = autoExclusive; #endif QWidget *f = QApplication::focusWidget(); QAbstractButton *fb = qobject_cast<QAbstractButton *>(f); if (!fb || !buttonList.contains(fb)) return; QAbstractButton *candidate = 0; int bestScore = -1; QRect target = f->rect().translated(f->mapToGlobal(QPoint(0,0))); QPoint goal = target.center(); uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus; for (int i = 0; i < buttonList.count(); ++i) { QAbstractButton *button = buttonList.at(i); if (button != f && button->window() == f->window() && button->isEnabled() && !button->isHidden() && (autoExclusive || (button->focusPolicy() & focus_flag) == focus_flag)) { QRect buttonRect = button->rect().translated(button->mapToGlobal(QPoint(0,0))); QPoint p = buttonRect.center(); //Priority to widgets that overlap on the same coordinate. //In that case, the distance in the direction will be used as significant score, //take also in account orthogonal distance in case two widget are in the same distance. int score; if ((buttonRect.x() < target.right() && target.x() < buttonRect.right()) && (key == Qt::Key_Up || key == Qt::Key_Down)) { //one item's is at the vertical of the other score = (qAbs(p.y() - goal.y()) << 16) + qAbs(p.x() - goal.x()); } else if ((buttonRect.y() < target.bottom() && target.y() < buttonRect.bottom()) && (key == Qt::Key_Left || key == Qt::Key_Right) ) { //one item's is at the horizontal of the other score = (qAbs(p.x() - goal.x()) << 16) + qAbs(p.y() - goal.y()); } else { score = (1 << 30) + (p.y() - goal.y()) * (p.y() - goal.y()) + (p.x() - goal.x()) * (p.x() - goal.x()); } if (score > bestScore && candidate) continue; switch(key) { case Qt::Key_Up: if (p.y() < goal.y()) { candidate = button; bestScore = score; } break; case Qt::Key_Down: if (p.y() > goal.y()) { candidate = button; bestScore = score; } break; case Qt::Key_Left: if (p.x() < goal.x()) { candidate = button; bestScore = score; } break; case Qt::Key_Right: if (p.x() > goal.x()) { candidate = button; bestScore = score; } break; } } } if (exclusive #ifdef QT_KEYPAD_NAVIGATION && !QApplication::keypadNavigationEnabled() #endif && candidate && fb->d_func()->checked && candidate->d_func()->checkable) candidate->click(); if (candidate) { if (key == Qt::Key_Up || key == Qt::Key_Left) candidate->setFocus(Qt::BacktabFocusReason); else candidate->setFocus(Qt::TabFocusReason); } }
// Draws a cached pixmap with shadow void FancyTabBar::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset) { QPixmap cache; QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); if (!QPixmapCache::find(pixmapName, cache)) { // High-dpi support: The in parameters (rect, radius, offset) are in // device-independent pixels. The call to QIcon::pixmap() below might // return a high-dpi pixmap, which will in that case have a devicePixelRatio // different than 1. The shadow drawing caluculations are done in device // pixels. QPixmap px = icon.pixmap(rect.size()); //jassuncao int devicePixelRatio = qCeil(px.devicePixelRatio()); int devicePixelRatio = 1; int radius = dipRadius * devicePixelRatio; QPoint offset = dipOffset * devicePixelRatio; 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(QRect(radius, radius, px.width(), px.height()), 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(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px); //jassuncao: cache.setDevicePixelRatio(devicePixelRatio); QPixmapCache::insert(pixmapName, cache); } QRect targetRect = cache.rect(); //jassuncao targetRect.setSize(targetRect.size() / cache.devicePixelRatio()); targetRect.moveCenter(rect.center() - dipOffset); p->drawPixmap(targetRect, cache); }
void FLFormRecordDB::setMainWidget( QWidget * w ) { if ( !cursor_ || !w ) return ; if ( !cursor_->metadata() ) return ; if ( showed ) { if ( mainWidget_ && mainWidget_ != w ) initMainWidget( w ); } else w->hide(); if ( pushButtonAcceptContinue ) pushButtonAcceptContinue->hide(); if ( pushButtonAccept ) pushButtonAccept->hide(); if ( pushButtonCancel ) pushButtonCancel->hide(); if ( pushButtonFirst ) pushButtonFirst->hide(); if ( pushButtonPrevious ) pushButtonPrevious->hide(); if ( pushButtonNext ) pushButtonNext->hide(); if ( pushButtonLast ) pushButtonLast->hide(); if ( layoutButtons ) delete layoutButtons; if ( layout ) delete layout; w->setFont( qApp->font() ); layout = new QVBoxLayout( this, 2, 3, "vlay" + name_ ); layout->add( w ); layoutButtons = new QHBoxLayout( layout, 3, "hlay" + name_ ) ; QSpacerItem *spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); QSize pbSize( 26, 26 ); #ifdef FL_DEBUGGER if ( !pushButtonIDE ) { pushButtonIDE = new QPushButton( this, "pushButtonIDE" ); connect( pushButtonIDE, SIGNAL( clicked() ), this, SLOT( openIde() ) ); } pushButtonIDE->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonIDE->sizePolicy().hasHeightForWidth() ) ); pushButtonIDE->setMinimumSize( pbSize ); pushButtonIDE->setMaximumSize( pbSize ); QPixmap qsa( QPixmap::fromMimeSource( "bug.png" ) ); pushButtonIDE->setIconSet( qsa ); pushButtonIDE->setAccel( QKeySequence( Qt::Key_F3 ) ); QToolTip::add( pushButtonIDE, tr( "Abrir Depurador (F3)" ) ); QWhatsThis::add( pushButtonIDE, tr( "Abrir Depurador (F3)" ) ); pushButtonIDE->setFocusPolicy( QWidget::NoFocus ); layoutButtons->addWidget( pushButtonIDE ); connect( pushButtonIDE, SIGNAL( clicked() ), this, SLOT( openIde() ) ); #endif layoutButtons->addItem( spacer_2 ); if ( cursor_->modeAccess() == FLSqlCursor::EDIT || cursor_->modeAccess() == FLSqlCursor::BROWSE ) { if ( !pushButtonFirst ) { pushButtonFirst = new QPushButton( this, "pushButtonFirst" ); connect( pushButtonFirst, SIGNAL( clicked() ), this, SLOT( firstRecord() ) ); } pushButtonFirst->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonFirst->sizePolicy().hasHeightForWidth() ) ); pushButtonFirst->setMinimumSize( pbSize ); pushButtonFirst->setMaximumSize( pbSize ); QPixmap rld( QPixmap::fromMimeSource( "first.png" ) ); pushButtonFirst->setIconSet( rld ); pushButtonFirst->setAccel( QKeySequence( Qt::Key_F5 ) ); QToolTip::add( pushButtonFirst, tr( "Aceptar los cambios e ir al primer registro (F5)" ) ); QWhatsThis::add( pushButtonFirst, tr( "Aceptar los cambios e ir al primer registro (F5)" ) ); pushButtonFirst->setFocusPolicy( QWidget::NoFocus ); layoutButtons->addWidget( pushButtonFirst ); pushButtonFirst->show(); if ( !pushButtonPrevious ) { pushButtonPrevious = new QPushButton( this, "pushButtonPrevious" ); connect( pushButtonPrevious, SIGNAL( clicked() ), this, SLOT( previousRecord() ) ); } pushButtonPrevious->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonPrevious->sizePolicy().hasHeightForWidth() ) ); pushButtonPrevious->setMinimumSize( pbSize ); pushButtonPrevious->setMaximumSize( pbSize ); QPixmap rld2( QPixmap::fromMimeSource( "previous.png" ) ); pushButtonPrevious->setIconSet( rld2 ); pushButtonPrevious->setAccel( QKeySequence( Qt::Key_F6 ) ); QToolTip::add( pushButtonPrevious, tr( "Aceptar los cambios e ir al registro anterior (F6)" ) ); QWhatsThis::add( pushButtonPrevious, tr( "Aceptar los cambios e ir al registro anterior (F6)" ) ); pushButtonPrevious->setFocusPolicy( QWidget::NoFocus ); layoutButtons->addWidget( pushButtonPrevious ); pushButtonPrevious->show(); if ( !pushButtonNext ) { pushButtonNext = new QPushButton( this, "pushButtonNext" ); connect( pushButtonNext, SIGNAL( clicked() ), this, SLOT( nextRecord() ) ); } pushButtonNext->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonNext->sizePolicy().hasHeightForWidth() ) ); pushButtonNext->setMinimumSize( pbSize ); pushButtonNext->setMaximumSize( pbSize ); QPixmap rld3( QPixmap::fromMimeSource( "next.png" ) ); pushButtonNext->setIconSet( rld3 ); pushButtonNext->setAccel( QKeySequence( Qt::Key_F7 ) ); QToolTip::add( pushButtonNext, tr( "Aceptar los cambios e ir al registro siguiente (F7)" ) ); QWhatsThis::add( pushButtonNext, tr( "Aceptar los cambios e ir al registro siguiente (F7)" ) ); pushButtonNext->setFocusPolicy( QWidget::NoFocus ); layoutButtons->addWidget( pushButtonNext ); pushButtonNext->show(); if ( !pushButtonLast ) { pushButtonLast = new QPushButton( this, "pushButtonLast" ); connect( pushButtonLast, SIGNAL( clicked() ), this, SLOT( lastRecord() ) ); } pushButtonLast->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonLast->sizePolicy().hasHeightForWidth() ) ); pushButtonLast->setMinimumSize( pbSize ); pushButtonLast->setMaximumSize( pbSize ); QPixmap rld4( QPixmap::fromMimeSource( "last.png" ) ); pushButtonLast->setIconSet( rld4 ); pushButtonLast->setAccel( QKeySequence( Qt::Key_F8 ) ); QToolTip::add( pushButtonLast, tr( "Aceptar los cambios e ir al último registro (F8)" ) ); QWhatsThis::add( pushButtonLast, tr( "Aceptar los cambios e ir al último registro (F8)" ) ); pushButtonLast->setFocusPolicy( QWidget::NoFocus ); layoutButtons->addWidget( pushButtonLast ); pushButtonLast->show(); } if ( cursor_->modeAccess() != FLSqlCursor::BROWSE ) { if ( showAcceptContinue_ ) { if ( !pushButtonAcceptContinue ) { pushButtonAcceptContinue = new QPushButton( this, "pushButtonAcceptContinue" ); connect( pushButtonAcceptContinue, SIGNAL( clicked() ), this, SLOT( acceptContinue() ) ); } pushButtonAcceptContinue->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonAcceptContinue->sizePolicy().hasHeightForWidth() ) ); pushButtonAcceptContinue->setMinimumSize( pbSize ); pushButtonAcceptContinue->setMaximumSize( pbSize ); QPixmap rld( QPixmap::fromMimeSource( "reload.png" ) ); pushButtonAcceptContinue->setIconSet( rld ); pushButtonAcceptContinue->setFocusPolicy( QWidget::NoFocus ); pushButtonAcceptContinue->setAccel( QKeySequence( Qt::Key_F9 ) ); QToolTip::add( pushButtonAcceptContinue, tr( "Aceptar los cambios y continuar con la edición de un nuevo registro (F9)" ) ); QWhatsThis::add( pushButtonAcceptContinue, tr( "Aceptar los cambios y continuar con la edición de un nuevo registro (F9)" ) ); layoutButtons->addWidget( pushButtonAcceptContinue ); pushButtonAcceptContinue->show(); } if ( !pushButtonAccept ) { pushButtonAccept = new QPushButton( this, "pushButtonAccept" ); connect( pushButtonAccept, SIGNAL( clicked() ), this, SLOT( accept() ) ); } pushButtonAccept->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonAccept->sizePolicy().hasHeightForWidth() ) ); pushButtonAccept->setMinimumSize( pbSize ); pushButtonAccept->setMaximumSize( pbSize ); QPixmap ok( QPixmap::fromMimeSource( "button_ok.png" ) ); pushButtonAccept->setIconSet( ok ); pushButtonAccept->setFocusPolicy( QWidget::NoFocus ); pushButtonAccept->setAccel( QKeySequence( Qt::Key_F10 ) ); QToolTip::add( pushButtonAccept, tr( "Aceptar los cambios y cerrar formulario (F10)" ) ); QWhatsThis::add( pushButtonAccept, tr( "Aceptar los cambios y cerrar formulario (F10)" ) ); layoutButtons->addWidget( pushButtonAccept ); pushButtonAccept->show(); } if ( !pushButtonCancel ) { pushButtonCancel = new QPushButton( this, "pushButtonCancel" ); connect( cursor_, SIGNAL( autoCommit() ), this, SLOT( disablePushButtonCancel() ) ); connect( pushButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); } pushButtonCancel->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0, pushButtonCancel->sizePolicy().hasHeightForWidth() ) ); pushButtonCancel->setMinimumSize( pbSize ); pushButtonCancel->setMaximumSize( pbSize ); QPixmap cancel( QPixmap::fromMimeSource( "button_cancel.png" ) ); pushButtonCancel->setIconSet( cancel ); if ( cursor_->modeAccess() != FLSqlCursor::BROWSE ) { pushButtonCancel->setFocusPolicy( QWidget::NoFocus ); pushButtonCancel->setAccel( 4096 ); QToolTip::add( pushButtonCancel, tr( "Cancelar los cambios y cerrar formulario (Esc)" ) ); QWhatsThis::add( pushButtonCancel, tr( "Cancelar los cambios y cerrar formulario (Esc)" ) ); } else { QPixmap ok( QPixmap::fromMimeSource( "button_cancel.png" ) ); pushButtonCancel->setIconSet( ok ); pushButtonCancel->setFocusPolicy( QWidget::StrongFocus ); pushButtonCancel->setFocus(); pushButtonCancel->setAccel( 4096 ); QToolTip::add( pushButtonCancel, tr( "Aceptar y cerrar formulario (Esc)" ) ); QWhatsThis::add( pushButtonCancel, tr( "Aceptar y cerrar formulario (Esc)" ) ); } pushButtonCancel->setDefault( true ); layoutButtons->addWidget( pushButtonCancel ); pushButtonCancel->show(); mainWidget_ = w; mainWidget_->setFocusPolicy( QWidget::NoFocus ); int mWidth = mainWidget_->width(); int mHeight = mainWidget_->height(); QWidget * actWin = qApp->activeWindow(); QRect screen = ( actWin ? actWin->geometry() : qApp->mainWidget()->geometry() ); QRect desk = QApplication::desktop()->geometry(); QPoint p = screen.center() - QPoint( mWidth / 2, mHeight / 2 ); if ( p.x() + mWidth > desk.width() ) p.setX( desk.width() - mWidth ); if ( p.y() + mHeight > desk.height() ) p.setY( desk.height() - mHeight ); if ( p.x() < 0 ) p.setX( 0 ); if ( p.y() < 0 ) p.setY( 0 ); move( p ); }
void PictureLabel::rotate(qreal angle, Qt::Axis axis) { if (!m_ori.isNull() && m_angle != angle) { //m_angle = Converter::rotation(m_angle, angle); QTransform trans; trans.translate(m_ori.width() / 2, m_ori.height() / 2).rotate(angle, axis); m_ori = m_ori.transformed(trans, Qt::SmoothTransformation); //m_ori = m_ori.transformed(QTransform().rotate(angle, axis), Qt::SmoothTransformation); int width = m_scaled.width(), height = m_scaled.height(); // static bool rotated = false; // if (!rotated) // { // rotated = true; // QRect rect = this->geometry(); // qDebug() << __FILE__ << __LINE__ << m_scaled << rect << rect.center(); // } if (Qt::YAxis == axis && 180 == angle && m_angle) { m_angle *= -1; } if (Qt::ZAxis == axis) { m_angle = angle; m_axis = axis; if (angle) { if (0 > angle) { angle *= -1; } if (90 < angle) { angle = 180 - angle; } qreal arc = angle * 3.1415926535 / 180; int sw = qCos(arc) * width + qSin(arc) * height; int sh = qCos(arc) * height + qSin(arc) * width; width = sw; height = sh; } else { width = m_default.width() + 2 * MARGIN_SPACE; height = m_default.height() + 2 * MARGIN_SPACE; } } m_bk = m_ori.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); m_size = m_bk.size(); QRect old = this->geometry(); //qDebug() << __FILE__ << __LINE__ << "before:" << m_size << m_angle << width << height << old.center(); setFixedSize(m_size); QRect curr = this->geometry(); curr.moveCenter(old.center()); setGeometry(curr); setPixmap(m_bk); //qDebug() << __FILE__ << __LINE__ << "after:" << curr << this->geometry().center(); } else { m_angle = 0; } }
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawPrimitive(element, option, painter, widget); bool animating = (option->state & State_Animating); int state = option->state; QRect rect = option->rect; QRect oldRect; QRect newRect; if (widget && (element == PE_PanelButtonTool) && !animating) { QWidget *w = const_cast<QWidget *> (widget); int oldState = w->property("_q_stylestate").toInt(); oldRect = w->property("_q_stylerect").toRect(); newRect = w->rect(); w->setProperty("_q_stylestate", (int)option->state); w->setProperty("_q_stylerect", w->rect()); // Determine the animated transition bool doTransition = ((state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver)); if (oldRect != newRect) { doTransition = false; d->animator.stopAnimation(widget); } if (doTransition) { QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); Animation *anim = d->animator.widgetAnimation(widget); QStyleOption opt = *option; opt.state = (QStyle::State)oldState; opt.state |= (State)State_Animating; startImage.fill(0); Transition *t = new Transition; t->setWidget(w); QPainter startPainter(&startImage); if (!anim) { drawPrimitive(element, &opt, &startPainter, widget); } else { anim->paint(&startPainter, &opt); d->animator.stopAnimation(widget); } QStyleOption endOpt = *option; endOpt.state |= (State)State_Animating; t->setStartImage(startImage); d->animator.startAnimation(t); endImage.fill(0); QPainter endPainter(&endImage); drawPrimitive(element, &endOpt, &endPainter, widget); t->setEndImage(endImage); if (oldState & State_MouseOver) t->setDuration(150); else t->setDuration(75); t->setStartTime(QTime::currentTime()); } } switch (element) { case PE_IndicatorDockWidgetResizeHandle: painter->fillRect(option->rect, Utils::StyleHelper::borderColor()); break; case PE_FrameDockWidget: QCommonStyle::drawPrimitive(element, option, painter, widget); break; case PE_PanelLineEdit: { painter->save(); // Fill the line edit background QRect filledRect = option->rect.adjusted(1, 1, -1, -1); painter->setBrushOrigin(filledRect.topLeft()); painter->fillRect(filledRect, option->palette.base()); if (option->state & State_Enabled) Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5); else Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5); if (option->state & State_HasFocus || option->state & State_MouseOver) { QColor hover = Utils::StyleHelper::baseColor(); if (state & State_HasFocus) hover.setAlpha(100); else hover.setAlpha(50); painter->setPen(QPen(hover, 1)); painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2)); } painter->restore(); } break; case PE_FrameStatusBarItem: break; case PE_PanelButtonTool: { Animation *anim = d->animator.widgetAnimation(widget); if (!animating && anim) { anim->paint(painter, option); } else { bool pressed = option->state & State_Sunken || option->state & State_On; QColor shadow(0, 0, 0, 30); painter->setPen(shadow); if (pressed) { QColor shade(0, 0, 0, 40); painter->fillRect(rect, shade); painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); // painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); QColor highlight(255, 255, 255, 30); painter->setPen(highlight); } else if (option->state & State_Enabled && option->state & State_MouseOver) { QColor lighter(255, 255, 255, 37); painter->fillRect(rect, lighter); } if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) { QColor highlight = option->palette.highlight().color(); highlight.setAlphaF(0.4); painter->setPen(QPen(highlight.lighter(), 1)); highlight.setAlphaF(0.3); painter->setBrush(highlight); painter->setRenderHint(QPainter::Antialiasing); QRectF rect = option->rect; rect.translate(0.5, 0.5); painter->drawRoundedRect(rect.adjusted(2, 2, -3, -3), 2, 2); } } } break; case PE_PanelStatusBar: { painter->save(); QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom())); QColor startColor = Utils::StyleHelper::shadowColor().darker(164); QColor endColor = Utils::StyleHelper::baseColor().darker(130); grad.setColorAt(0, startColor); grad.setColorAt(1, endColor); painter->fillRect(option->rect, grad); painter->setPen(QColor(255, 255, 255, 60)); painter->drawLine(rect.topLeft() + QPoint(0,1), rect.topRight()+ QPoint(0,1)); painter->setPen(Utils::StyleHelper::borderColor().darker(110)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->restore(); } break; case PE_IndicatorToolBarSeparator: { QColor separatorColor = Utils::StyleHelper::borderColor(); separatorColor.setAlpha(100); painter->setPen(separatorColor); const int margin = 6; if (option->state & State_Horizontal) { const int offset = rect.width()/2; painter->drawLine(rect.bottomLeft().x() + offset, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset, rect.topLeft().y() + margin); } else { //Draw vertical separator const int offset = rect.height()/2; painter->setPen(QPen(option->palette.background().color().darker(110))); painter->drawLine(rect.topLeft().x() + margin , rect.topLeft().y() + offset, rect.topRight().x() - margin, rect.topRight().y() + offset); } } break; case PE_IndicatorToolBarHandle: { bool horizontal = option->state & State_Horizontal; painter->save(); QPainterPath path; int x = option->rect.x() + (horizontal ? 2 : 6); int y = option->rect.y() + (horizontal ? 6 : 2); static const int RectHeight = 2; if (horizontal) { while (y < option->rect.height() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); y += 6; } } else { while (x < option->rect.width() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); x += 6; } } painter->setPen(Qt::NoPen); QColor dark = Utils::StyleHelper::borderColor(); dark.setAlphaF(0.4); QColor light = Utils::StyleHelper::baseColor(); light.setAlphaF(0.4); painter->fillPath(path, light); painter->save(); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); painter->translate(3, 3); painter->fillPath(path, light); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); } break; case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { Utils::StyleHelper::drawArrow(element, painter, option); } break; default: QProxyStyle::drawPrimitive(element, option, painter, widget); break; } }
int PhpWebView::click(const QString & xpath, bool samewnd) { QWebElement elem = getElementByXPath(QString(xpath)); if (elem.isNull()) return 0; elem.setFocus(); if (samewnd) elem.removeAttribute("target"); QString js = "var node = this; var x = node.offsetLeft; var y = node.offsetTop; "; js += "var w = node.offsetWidth/2; "; js += "var h = node.offsetHeight/2; "; js += "while (node.offsetParent != null) { "; js += " node = node.offsetParent; "; js += " x += node.offsetLeft; "; js += " y += node.offsetTop; "; js += "} "; js += "[x+w, y+h]; "; QList<QVariant> vlist = elem.evaluateJavaScript(js).toList(); QPoint point; point.setX(vlist.at(0).toInt()); point.setY(vlist.at(1).toInt()); QRect elGeom = elem.geometry(); QPoint elPoint = elGeom.center(); int elX = point.x(); //elPoint.x(); int elY = point.y(); //elPoint.y(); int webWidth = width(); int webHeight = height(); int pixelsToScrollRight=0; int pixelsToScrollDown=0; if (elX > webWidth) pixelsToScrollRight = elX-webWidth+elGeom.width()/2+50; //the +10 part if for the page to scroll a bit further if (elY > webHeight) pixelsToScrollDown = elY-webHeight+elGeom.height()/2+50; //the +10 part if for the page to scroll a bit further /*pixelsToScrollRight = elX-elGeom.width()/2-50; pixelsToScrollDown = elY-elGeom.height()/2-50; if (pixelsToScrollRight < 0) pixelsToScrollRight = 0; if (pixelsToScrollRight > page()->mainFrame()->scrollBarMaximum(Qt::Horizontal)) pixelsToScrollRight = page()->mainFrame()->scrollBarMaximum(Qt::Horizontal); if (pixelsToScrollDown < 0) pixelsToScrollDown = 0; if (pixelsToScrollDown > page()->mainFrame()->scrollBarMaximum(Qt::Vertical)) pixelsToScrollDown = page()->mainFrame()->scrollBarMaximum(Qt::Vertical);*/ int oldHoriz = page()->mainFrame()->scrollBarValue(Qt::Horizontal); int oldVert = page()->mainFrame()->scrollBarValue(Qt::Vertical); page()->mainFrame()->setScrollBarValue(Qt::Horizontal, pixelsToScrollRight); page()->mainFrame()->setScrollBarValue(Qt::Vertical, pixelsToScrollDown); QPoint pointToClick(elX-pixelsToScrollRight, elY-pixelsToScrollDown); QEventLoop loop; isNewViewCreated = false; isNewViewBegin = false; //QMouseEvent *pressEvent = new QMouseEvent(QMouseEvent::MouseButtonPress, pointToClick, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); //QApplication::postEvent(browser, pressEvent); //QApplication::processEvents(); //QMouseEvent releaseEvent(QMouseEvent::MouseButtonRelease,pointToClick,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier); //QApplication::sendEvent(browser, &releaseEvent); QString js2 = "var e = document.createEvent('MouseEvents');"; //js2 += "e.initEvent( 'click', true, true );"; //js2 += "e.initMouseEvent('click', true, true, window, 0, 0, 0, "+QString::number(elX)+", "+QString::number(elY)+", false, false, false, false, 0, null);"; js2 += "e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"; js2 += "this.dispatchEvent(e);"; elem.evaluateJavaScript(js2); QTimer::singleShot(1000, &loop, SLOT(quit())); loop.exec(); while (browser && isNewViewBegin && !isNewViewCreated) loop.processEvents(); //page()->mainFrame()->setScrollBarValue(Qt::Horizontal, oldHoriz); //page()->mainFrame()->setScrollBarValue(Qt::Vertical, oldVert); return 1; }
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette, lightColored(widget)); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu && !widget->property("noArrow").toBool()) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; bool drawborder = !(widget && widget->property("hideborder").toBool()); bool alignarrow = !(widget && widget->property("alignarrow").toBool()); // Draw tool button if (drawborder) { QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); } QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); if (drawborder) painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (!alignarrow) { int labelwidth = option->fontMetrics.width(cb->currentText); if (reverse) arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4)); else arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4)); } if (option->state & State_On) arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget), QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: QProxyStyle::drawComplexControl(control, option, painter, widget); break; } }
void FilmstripFrames::paintEvent(QPaintEvent *evt) { QPainter p(this); // p.setRenderHint(QPainter::Antialiasing, true); QRect clipRect = evt->rect(); p.fillRect(clipRect, Qt::black); // thumbnail rect, including offsets QRect iconImgRect = QRect(QPoint(fs_leftMargin + fs_iconMarginLR, fs_frameSpacing / 2 + fs_iconMarginTop), m_iconSize); // frame size with margins QSize frameSize = m_iconSize + QSize(fs_iconMarginLR * 2, fs_iconMarginTop + fs_iconMarginBottom); // .. and with offset QRect frameRect = QRect(QPoint(fs_leftMargin, fs_frameSpacing / 2), frameSize); int oneFrameHeight = frameSize.height() + fs_frameSpacing; // visible frame index range int i0 = y2index(clipRect.top()); int i1 = y2index(clipRect.bottom()); // fids, frameCount <- frames del livello std::vector<TFrameId> fids; TXshSimpleLevel *sl = getLevel(); if (sl) sl->getFids(fids); else { for (int i = i0; i <= i1; i++) { // draw white rectangles if obtaining the level is failed QRect iconRect = frameRect.translated(QPoint(0, oneFrameHeight * i)); p.setBrush(QColor(192, 192, 192)); p.setPen(Qt::NoPen); p.drawRect(iconRect); } return; } //--- compute navigator rect --- QRect naviRect; ComboViewerPanel *inknPaintViewerPanel = TApp::instance()->getInknPaintViewerPanel(); if (sl->getType() == TZP_XSHLEVEL && inknPaintViewerPanel) { // show navigator only if the inknpaint viewer is visible if (inknPaintViewerPanel->isVisible()) { SceneViewer *viewer = inknPaintViewerPanel->getSceneViewer(); // imgSize: image's pixel size QSize imgSize(sl->getProperties()->getImageRes().lx, sl->getProperties()->getImageRes().ly); // Viewer affine TAffine viewerAff = inknPaintViewerPanel->getSceneViewer()->getViewMatrix(); // pixel size which will be displayed with 100% scale in Viewer Stage TFrameId currentId = TApp::instance()->getCurrentFrame()->getFid(); double imgPixelWidth = (double)(imgSize.width()) / sl->getDpi(currentId).x * Stage::inch; double imgPixelHeight = (double)(imgSize.height()) / sl->getDpi(currentId).y * Stage::inch; // get the image's corner positions in viewer matrix (with current zoom // scale) TPointD imgTopRight = viewerAff * TPointD(imgPixelWidth / 2.0f, imgPixelHeight / 2.0f); TPointD imgBottomLeft = viewerAff * TPointD(-imgPixelWidth / 2.0f, -imgPixelHeight / 2.0f); // pixel size in viewer matrix ( with current zoom scale ) QSizeF imgSizeInViewer(imgTopRight.x - imgBottomLeft.x, imgTopRight.y - imgBottomLeft.y); // ratio of the Viewer frame's position and size QRectF naviRatio( (-(float)viewer->width() * 0.5f - (float)imgBottomLeft.x) / imgSizeInViewer.width(), 1.0f - ((float)viewer->height() * 0.5f - (float)imgBottomLeft.y) / imgSizeInViewer.height(), (float)viewer->width() / imgSizeInViewer.width(), (float)viewer->height() / imgSizeInViewer.height()); naviRect = QRect(iconImgRect.left() + (int)(naviRatio.left() * (float)iconImgRect.width()), iconImgRect.top() + (int)(naviRatio.top() * (float)iconImgRect.height()), (int)((float)iconImgRect.width() * naviRatio.width()), (int)((float)iconImgRect.height() * naviRatio.height())); // for drag move m_naviRectPos = naviRect.center(); naviRect = naviRect.intersected(frameRect); m_icon2ViewerRatio.setX(imgSizeInViewer.width() / (float)iconImgRect.width()); m_icon2ViewerRatio.setY(imgSizeInViewer.height() / (float)iconImgRect.height()); } } //--- compute navigator rect end --- int frameCount = (int)fids.size(); std::set<TFrameId> editableFrameRange; if (sl) editableFrameRange = sl->getEditableRange(); bool isReadOnly = false; if (sl) isReadOnly = sl->isReadOnly(); int i; int iconWidth = m_iconSize.width(); int x0 = m_frameLabelWidth; int x1 = x0 + iconWidth; int frameHeight = m_iconSize.height(); // linee orizzontali che separano i frames p.setPen(getLightLineColor()); for (i = i0; i <= i1; i++) { int y = index2y(i) + frameHeight; p.drawLine(0, y, x1, y); } TFilmstripSelection::InbetweenRange range = m_selection->getInbetweenRange(); // draw for each frames for (i = i0; i <= i1; i++) { QRect tmp_iconImgRect = iconImgRect.translated(QPoint(0, oneFrameHeight * i)); QRect tmp_frameRect = frameRect.translated(QPoint(0, oneFrameHeight * i)); bool isCurrentFrame = (i == sl->fid2index(TApp::instance()->getCurrentFrame()->getFid())); bool isSelected = (0 <= i && i < frameCount && m_selection->isSelected(fids[i])); if (0 <= i && i < frameCount) { TFrameId fid = fids[i]; // normal or inbetween (for vector levels) int flags = (sl->getType() == PLI_XSHLEVEL && range.first < fid && fid < range.second) ? F_INBETWEEN_RANGE : F_NORMAL; // draw icons drawFrameIcon(p, tmp_iconImgRect, i, fid, flags); p.setPen(Qt::NoPen); p.setBrush(Qt::NoBrush); p.drawRect(tmp_iconImgRect); // Frame number if (m_selection->isSelected(fids[i])) { if (TApp::instance()->getCurrentFrame()->isEditingLevel() && isCurrentFrame) p.setPen(Qt::red); else p.setPen(Qt::white); } else p.setPen(QColor(192, 192, 192)); p.setBrush(Qt::NoBrush); // for single frame QString text; if (fid.getNumber() == TFrameId::EMPTY_FRAME || fid.getNumber() == TFrameId::NO_FRAME) { text = QString("Single Frame"); } // for sequencial frame (with letter) else if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) { text = fidToFrameNumberWithLetter(fid.getNumber()); } // for sequencial frame else { text = QString::number(fid.getNumber()).rightJustified(4, '0'); } p.drawText(tmp_frameRect.adjusted(0, 0, -3, 2), text, QTextOption(Qt::AlignRight | Qt::AlignBottom)); p.setPen(Qt::NoPen); // Read-only frames (lock) if (0 <= i && i < frameCount) { if ((editableFrameRange.empty() && isReadOnly) || (isReadOnly && (!editableFrameRange.empty() && editableFrameRange.count(fids[i]) == 0))) { static QPixmap lockPixmap(":Resources/forbidden.png"); p.drawPixmap(tmp_frameRect.bottomLeft() + QPoint(3, -13), lockPixmap); } } } // navigator rect if (naviRect.isValid() && isCurrentFrame) { p.setPen(QPen(Qt::red, 1)); p.drawRect(naviRect.translated(0, oneFrameHeight * i)); p.setPen(Qt::NoPen); } // red frame for the current frame if (TApp::instance()->getCurrentFrame()->isEditingLevel() && (isCurrentFrame || isSelected)) { QPen pen; pen.setColor(Qt::red); pen.setWidth(2); pen.setJoinStyle(Qt::RoundJoin); p.setPen(pen); p.drawRect(tmp_frameRect.adjusted(-1, -1, 2, 2)); p.setPen(Qt::NoPen); } } // se sono in modalita' level edit faccio vedere la freccia che indica il // frame corrente if (TApp::instance()->getCurrentFrame()->isEditingLevel()) m_frameHeadGadget->draw(p, QColor(Qt::white), QColor(Qt::black)); }
void TrayIcon::draw(QPaintEvent* /*event*/) { Display* dsp = QX11Info::display(); XWindowAttributes attr; if (!XGetWindowAttributes(dsp, mIconId, &attr)) { qWarning() << "Paint error"; return; } XImage* ximage = XGetImage(dsp, mIconId, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); if (!ximage) { qWarning() << " * Error image is NULL"; return; } // qDebug() << "Paint icon **************************************"; // qDebug() << " * XComposite: " << isXCompositeAvailable(); // qDebug() << " * Icon geometry:" << iconGeometry(); // qDebug() << " Icon"; // qDebug() << " * window id: " << hex << mIconId; // qDebug() << " * window name:" << xfitMan().getName(mIconId); // qDebug() << " * size (WxH): " << attr.width << "x" << attr.height; // qDebug() << " * pos (XxY): " << attr.x << attr.y; // qDebug() << " * color depth:" << attr.depth; // qDebug() << " XImage"; // qDebug() << " * size (WxH): " << ximage->width << "x" << ximage->height; // switch (ximage->format) // { // case XYBitmap: qDebug() << " * format: XYBitmap"; break; // case XYPixmap: qDebug() << " * format: XYPixmap"; break; // case ZPixmap: qDebug() << " * format: ZPixmap"; break; // } // qDebug() << " * color depth: " << ximage->depth; // qDebug() << " * bits per pixel:" << ximage->bits_per_pixel; //const uchar* d =(uchar*) ximage->data; QImage image = QImage((const uchar*) ximage->data, ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_ARGB32_Premultiplied); // Draw QImage ........................... QPainter painter(this); QRect iconRect = iconGeometry(); if (image.size() != iconRect.size()) { image = image.scaled(iconRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QRect r = image.rect(); r.moveCenter(iconRect.center()); iconRect = r; } // qDebug() << " Draw rect:" << iconRect; painter.drawImage(iconRect, image); XDestroyImage(ximage); // debug << "End paint icon **********************************"; }
void ProxyWidget::paintEvent(QPaintEvent *ev) { ev->accept(); if ( isTriggered ) { QPainter painter(this); painter.eraseRect(commonRect); return; }; if ( usedViewMode==SOFT_TOUCHED ) { QPainter painter(this); if ( commonRect.intersects(ev->rect()) ) { painter.setOpacity(0.20); painter.drawPixmap( commonRect.adjusted( (commonRect.width()-4*side)/2, (commonRect.height()-4*side)/2, -(commonRect.width()-4*side)/2, -(commonRect.height()-4*side)/2), emblem.scaled( commonRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.setOpacity(1); QRect rF; QPoint dR1, dR3, dR5, dR6, dR7, dR8, dR9; if ( r1.intersects(currRect) ) { rF = r1; dR1 = QPoint(5, 5); } else if ( r3.intersects(currRect) ) { rF = r3; dR3 = QPoint(5, 5); } else if ( r5.intersects(currRect) ) { rF = r5; dR5 = QPoint(5, 5); } else if ( r6.intersects(currRect) ) { rF = r6; dR6 = QPoint(5, 5); } else if ( r7.intersects(currRect) ) { rF = r7; dR7 = QPoint(5, 5); } else if ( r8.intersects(currRect) ) { rF = r8; dR8 = QPoint(5, 5); } else if ( r9.intersects(currRect) ) { rF = r9; dR9 = QPoint(5, 5); }; QRadialGradient gradient( rF.center().x(), rF.center().y()+side/3, side/2); gradient.setColorAt( 1, QColor::fromRgb(173, 255, 47, 25)); // green gradient.setColorAt( 0, QColor::fromRgb(255, 215, 0, 255)); // gold QBrush b(gradient); painter.setBrush(b); painter.setPen(QPen(QBrush(), 0)); QPoint p = QPoint( rF.center().x(), rF.center().y()+side/4); rF.moveCenter(p); painter.drawEllipse(rF); painter.setOpacity(1); painter.drawPixmap( r1.adjusted( (r1.width()-side)/2+dR1.x(), (r1.height()-side)/2+dR1.y(), -(r1.width()-side)/2+dR1.x(), -(r1.height()-side)/2+dR1.y()), connections.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap( r3.adjusted( (r3.width()-side)/2+dR3.x(), (r3.height()-side)/2+dR3.y(), -(r3.width()-side)/2+dR3.x(), -(r3.height()-side)/2+dR3.y()), domains.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap( r5.adjusted( (r5.width()-side)/2+dR5.x(), (r5.height()-side)/2+dR5.y(), -(r5.width()-side)/2+dR5.x(), -(r5.height()-side)/2+dR5.y()), networks.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap( r6.adjusted( (r6.width()-side)/2+dR6.x(), (r6.height()-side)/2+dR6.y(), -(r6.width()-side)/2+dR6.x(), -(r6.height()-side)/2+dR6.y()), storages.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap( r7.adjusted( (r7.width()-side)/2+dR7.x(), (r7.height()-side)/2+dR7.y(), -(r7.width()-side)/2+dR7.x(), -(r7.height()-side)/2+dR7.y()), secrets.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap( r8.adjusted( (r8.width()-side)/2+dR8.x(), (r8.height()-side)/2+dR8.y(), -(r8.width()-side)/2+dR8.x(), -(r8.height()-side)/2+dR8.y()), ifaces.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap( r9.adjusted( (r9.width()-side)/2+dR9.x(), (r9.height()-side)/2+dR9.y(), -(r9.width()-side)/2+dR9.x(), -(r9.height()-side)/2+dR9.y()), log.scaled( part, Qt::KeepAspectRatio, Qt::SmoothTransformation)); }; QFont _font; _font.setBold(true); _font.setFamily("Monospace"); _font.setPixelSize(heightPart/8); painter.setFont(_font); //painter.setOpacity(0.50); painter.setPen(QColor::fromRgb(248, 248, 255, 255)); // ghostwhite if ( !r1.intersects(currRect) ) { painter.drawText( r1.adjusted(0, heightPart*2/3, 0, 0), Qt::AlignCenter, "Connections\nCtrl+Alt+C"); qDebug()<<"r1!=ev->rect()"<<r1; }; if ( !r3.intersects(currRect) ) { painter.drawText( r3.adjusted(0, heightPart/2, 0, 0), Qt::AlignCenter, "Virtual\nmachines\nCtrl+Alt+D"); qDebug()<<"r3!=ev->rect()"<<r3; }; if ( !r5.intersects(currRect) ) { painter.drawText( r5.adjusted(0, heightPart*2/3, 0, 0), Qt::AlignCenter, "Networks\nCtrl+Alt+N"); qDebug()<<"r5!=ev->rect()"<<r5; }; if ( !r6.intersects(currRect) ) { painter.drawText( r6.adjusted(0, heightPart*2/3, 0, 0), Qt::AlignCenter, "Storages\nCtrl+Alt+S"); qDebug()<<"r6!=ev->rect()"<<r6; }; if ( !r7.intersects(currRect) ) { painter.drawText( r7.adjusted(0, heightPart*2/3, 0, 0), Qt::AlignCenter, "Secrets\nCtrl+Alt+E"); qDebug()<<"r7!=ev->rect()"<<r7; }; if ( !r8.intersects(currRect) ) { painter.drawText( r8.adjusted(0, heightPart*2/3, 0, 0), Qt::AlignCenter, "Interfaces\nCtrl+Alt+I"); qDebug()<<"r8!=ev->rect()"<<r8; }; if ( !r9.intersects(currRect) ) { painter.drawText( r9.adjusted(0, heightPart*2/3, 0, 0), Qt::AlignCenter, "Log\nCtrl+Alt+G"); qDebug()<<"r9!=ev->rect()"<<r9; }; }; }
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); }
QWebElement WebPage::activeElement() const { QRect activeRect = inputMethodQuery(Qt::ImMicroFocus).toRect(); return mainFrame()->hitTestContent(activeRect.center()).element(); }
/*! \brief Draw the contents inside the frame QColorGroup::Background is the background color outside of the frame. QColorGroup::Base is the background color inside the frame. QColorGroup::Foreground is the background color inside the scale. \param painter Painter \sa QwtDial::boundingRect, QwtDial::contentsRect, QwtDial::scaleContentsRect, QWidget::setPalette */ void QwtDial::drawContents(QPainter *painter) const { if ( backgroundMode() == NoBackground || colorGroup().brush(QColorGroup::Base) != colorGroup().brush(QColorGroup::Background) ) { // Don´t use QPainter::drawEllipse. There are some pixels // different compared to the region in the mask, leaving // them in background color. painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(colorGroup().brush(QColorGroup::Base)); // Even if we want to fill the contentsRect only, we fill the // complete boundingRect. The frame will be painted later // above, but we want to have the base color below it // because round objects doesn´t cover all pixels. QRect br = boundingRect(); #if QT_VERSION < 300 #ifdef _WS_WIN32_ // Qt-230-NC draws ellipses not as nicely as Qt-2.3.x on X Windows br.setTop(br.top()-1); br.setLeft(br.left()-1); br.setBottom(br.bottom()+1); br.setRight(br.right()+1); #endif #endif painter->setClipRegion(QRegion(painter->xForm(br), QRegion::Ellipse)); painter->drawRect(br); painter->restore(); } const QRect insideScaleRect = scaleContentsRect(); if ( colorGroup().brush(QColorGroup::Foreground) != colorGroup().brush(QColorGroup::Base) ) { painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(colorGroup().brush(QColorGroup::Foreground)); painter->setClipRegion( QRegion(painter->xForm(insideScaleRect), QRegion::Ellipse)); painter->drawRect(insideScaleRect); painter->restore(); } const QPoint center = insideScaleRect.center(); const int radius = insideScaleRect.width() / 2; painter->save(); drawScaleContents(painter, center, radius); painter->restore(); double direction = d_origin; if (isValid()) { direction = d_origin + d_minScaleArc; if ( maxValue() > minValue() && d_maxScaleArc > d_minScaleArc ) { const double ratio = (value() - minValue()) / (maxValue() - minValue()); direction += ratio * (d_maxScaleArc - d_minScaleArc); } if ( direction >= 360.0 ) direction -= 360.0; } double origin = d_origin; if ( mode() == RotateScale ) { origin -= direction - d_origin; direction = d_origin; } painter->save(); drawScale(painter, center, radius, origin, d_minScaleArc, d_maxScaleArc); painter->restore(); if ( isValid() ) { QPalette::ColorGroup cg; if ( isEnabled() ) cg = hasFocus() ? QPalette::Active : QPalette::Inactive; else cg = QPalette::Disabled; painter->save(); drawNeedle(painter, center, radius, direction, cg); painter->restore(); } }
/*! \brief Draw the contents inside the frame QColorGroup::Background is the background color outside of the frame. QColorGroup::Base is the background color inside the frame. QColorGroup::Foreground is the background color inside the scale. \param painter Painter \sa QwtDial::boundingRect, QwtDial::contentsRect, QwtDial::scaleContentsRect, QWidget::setPalette */ void QwtDial::drawContents(QPainter *painter) const { #if QT_VERSION < 0x040000 if ( backgroundMode() == Qt::NoBackground || colorGroup().brush(QColorGroup::Base) != colorGroup().brush(QColorGroup::Background) ) #else if ( testAttribute(Qt::WA_NoSystemBackground) || palette().brush(QPalette::Base) != palette().brush(QPalette::Background) ) #endif { const QRect br = boundingRect(); painter->save(); painter->setPen(Qt::NoPen); #if QT_VERSION < 0x040000 painter->setBrush(colorGroup().brush(QColorGroup::Base)); #else painter->setBrush(palette().brush(QPalette::Base)); #endif painter->drawEllipse(br); painter->restore(); } const QRect insideScaleRect = scaleContentsRect(); #if QT_VERSION < 0x040000 if ( colorGroup().brush(QColorGroup::Foreground) != colorGroup().brush(QColorGroup::Base) ) #else if ( palette().brush(QPalette::Foreground) != palette().brush(QPalette::Base) ) #endif { painter->save(); painter->setPen(Qt::NoPen); #if QT_VERSION < 0x040000 painter->setBrush(colorGroup().brush(QColorGroup::Foreground)); #else painter->setBrush(palette().brush(QPalette::Foreground)); #endif painter->drawEllipse(insideScaleRect.x() - 1, insideScaleRect.y() - 1, insideScaleRect.width(), insideScaleRect.height() ); painter->restore(); } const QPoint center = insideScaleRect.center(); const int radius = insideScaleRect.width() / 2; painter->save(); drawScaleContents(painter, center, radius); painter->restore(); double direction = d_data->origin; if (isValid()) { direction = d_data->origin + d_data->minScaleArc; if ( maxValue() > minValue() && d_data->maxScaleArc > d_data->minScaleArc ) { const double ratio = (value() - minValue()) / (maxValue() - minValue()); direction += ratio * (d_data->maxScaleArc - d_data->minScaleArc); } if ( direction >= 360.0 ) direction -= 360.0; } double origin = d_data->origin; if ( mode() == RotateScale ) { origin -= direction - d_data->origin; direction = d_data->origin; } painter->save(); drawScale(painter, center, radius, origin, d_data->minScaleArc, d_data->maxScaleArc); painter->restore(); if ( isValid() ) { QPalette::ColorGroup cg; if ( isEnabled() ) cg = hasFocus() ? QPalette::Active : QPalette::Inactive; else cg = QPalette::Disabled; painter->save(); drawNeedle(painter, center, radius, direction, cg); painter->restore(); } }
void CCompass::Draw(QPainter *p_pPainter, QPoint *p_pCenter) { QBrush BkBrush, Brush[2], TextBrush; QPen Pen; QRect DrawRect; QColor Color; QPoint Points[3], TickPoints[24]; QFont Font; short i, Offset = 5, FontPixelSize = 15, TextWidth; char tstr[128]; double dCompassPosition; for(i = 0; i < 24; i += 2) { TickPoints[i].setX(p_pCenter->x() + 0); TickPoints[i].setY(p_pCenter->y() - m_nRadius); TickPoints[i + 1].setX(p_pCenter->x() + 0); TickPoints[i + 1].setY(p_pCenter->y() - m_nRadius + 2 * Offset + ((!(i % 3)) ? Offset : 0)); } DrawRect.setCoords(p_pCenter->x() - m_nRadius, p_pCenter->y() - m_nRadius, p_pCenter->x() + m_nRadius, p_pCenter->y() + m_nRadius); BkBrush = QBrush(QColor(255, 0, 0, 128)); TextBrush = QBrush(QColor(255, 255, 0, 255)); Brush[0] = QBrush(QColor(255, 0, 0, 255)); Brush[1] = QBrush(QColor(255, 255, 255, 255)); Pen = QPen(Qt::black); Pen.setWidth(1); Pen.setStyle(Qt::NoPen); p_pPainter->setPen(Pen); BkBrush.setStyle(Qt::SolidPattern); p_pPainter->setBrush(BkBrush); p_pPainter->drawEllipse(DrawRect.center(), m_nRadius - Offset, m_nRadius - Offset); BkBrush.setStyle(Qt::NoBrush); p_pPainter->setBrush(BkBrush); Pen.setStyle(Qt::SolidLine); p_pPainter->setPen(Pen); p_pPainter->drawEllipse(DrawRect.center(), m_nRadius, m_nRadius); for(i = 0; i < 12; i ++) RotatePoints(&(TickPoints[i * 2]), 2, p_pCenter, 30 * i); p_pPainter->drawLines(TickPoints, 12); Pen.setStyle(Qt::NoPen); p_pPainter->setPen(Pen); p_pPainter->setBrush(Brush[0]); Points[0].setX(p_pCenter->x() + Offset); Points[0].setY(p_pCenter->y()); Points[1].setX(p_pCenter->x() - Offset); Points[1].setY(p_pCenter->y()); Points[2].setX(p_pCenter->x()); Points[2].setY(p_pCenter->y() - m_nRadius + Offset); dCompassPosition = 360.0 - m_dHeading_deg; if(dCompassPosition < 0) dCompassPosition += 360; RotatePoints(Points, 3, p_pCenter, dCompassPosition); p_pPainter->drawConvexPolygon(Points, 3); p_pPainter->setBrush(Brush[1]); Points[0].setX(p_pCenter->x() + Offset); Points[0].setY(p_pCenter->y()); Points[1].setX(p_pCenter->x() - Offset); Points[1].setY(p_pCenter->y()); Points[2].setX(p_pCenter->x()); Points[2].setY(p_pCenter->y() + m_nRadius - Offset); RotatePoints(Points, 3, p_pCenter, dCompassPosition); p_pPainter->drawConvexPolygon(Points, 3); Pen.setColor(Qt::black); Pen.setStyle(Qt::SolidLine); p_pPainter->setPen(Pen); p_pPainter->setBrush(TextBrush); Font.setPixelSize(FontPixelSize); p_pPainter->setFont(Font); sprintf_s(tstr, sizeof(tstr), "%.0lf", m_dHeading_deg); QFontMetrics FontMetrics(Font); TextWidth = FontMetrics.width(tstr) + 4; DrawRect.setCoords(p_pCenter->x() - TextWidth / 2, p_pCenter->y() - FontPixelSize / 2, p_pCenter->x() + TextWidth / 2, p_pCenter->y() + FontPixelSize / 2 + 2); p_pPainter->drawRect(DrawRect); p_pPainter->drawText(DrawRect, Qt::AlignCenter, QString::fromLocal8Bit(tstr)); }
void FancyToolButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event) QPainter painter(this); // draw borders bool isTitledAction = defaultAction()->property("titledAction").toBool(); #ifndef Q_WS_MAC // Mac UIs usually don't hover if (m_fader > 0 && isEnabled() && !isDown() && !isChecked()) { painter.save(); int fader = int(40 * m_fader); QLinearGradient grad(rect().topLeft(), rect().topRight()); grad.setColorAt(0, Qt::transparent); grad.setColorAt(0.5, QColor(255, 255, 255, fader)); grad.setColorAt(1, Qt::transparent); painter.fillRect(rect(), grad); painter.setPen(QPen(grad, 1.0)); painter.drawLine(rect().topLeft(), rect().topRight()); painter.drawLine(rect().bottomLeft(), rect().bottomRight()); painter.restore(); } else #endif if (isDown() || isChecked()) { painter.save(); QLinearGradient grad(rect().topLeft(), rect().topRight()); grad.setColorAt(0, Qt::transparent); grad.setColorAt(0.5, QColor(0, 0, 0, 50)); grad.setColorAt(1, Qt::transparent); painter.fillRect(rect(), grad); painter.setPen(QPen(grad, 1.0)); painter.drawLine(rect().topLeft(), rect().topRight()); painter.drawLine(rect().topLeft(), rect().topRight()); painter.drawLine(rect().topLeft() + QPoint(0,1), rect().topRight() + QPoint(0,1)); painter.drawLine(rect().bottomLeft(), rect().bottomRight()); painter.drawLine(rect().bottomLeft(), rect().bottomRight()); painter.drawLine(rect().topLeft() - QPoint(0,1), rect().topRight() - QPoint(0,1)); painter.restore(); } QPixmap borderPixmap; QMargins margins; QRect iconRect(0, 0, Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE); // draw popup texts if (isTitledAction) { QFont normalFont(painter.font()); QRect centerRect = rect(); normalFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); QFont boldFont(normalFont); boldFont.setBold(true); QFontMetrics fm(normalFont); QFontMetrics boldFm(boldFont); int lineHeight = boldFm.height(); int textFlags = Qt::AlignVCenter|Qt::AlignHCenter; const QString projectName = defaultAction()->property("heading").toString(); if (!projectName.isNull()) centerRect.adjust(0, lineHeight + 4, 0, 0); const QString buildConfiguration = defaultAction()->property("subtitle").toString(); if (!buildConfiguration.isNull()) centerRect.adjust(0, 0, 0, -lineHeight - 4); iconRect.moveCenter(centerRect.center()); Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled); painter.setFont(normalFont); QPoint textOffset = centerRect.center() - QPoint(iconRect.width()/2, iconRect.height()/2); textOffset = textOffset - QPoint(0, lineHeight + 4); QRectF r(0, textOffset.y(), rect().width(), lineHeight); QColor penColor; if (isEnabled()) penColor = Qt::white; else penColor = Qt::gray; painter.setPen(penColor); const int margin = 6; QString ellidedProjectName = fm.elidedText(projectName, Qt::ElideMiddle, r.width() - margin); if (isEnabled()) { const QRectF shadowR = r.translated(0, 1); painter.setPen(QColor(30, 30, 30, 80)); painter.drawText(shadowR, textFlags, ellidedProjectName); painter.setPen(penColor); } painter.drawText(r, textFlags, ellidedProjectName); textOffset = iconRect.center() + QPoint(iconRect.width()/2, iconRect.height()/2); r = QRectF(0, textOffset.y()+5, rect().width(), lineHeight); painter.setFont(boldFont); QString ellidedBuildConfiguration = boldFm.elidedText(buildConfiguration, Qt::ElideMiddle, r.width() - margin); if (isEnabled()) { const QRectF shadowR = r.translated(0, 1); painter.setPen(QColor(30, 30, 30, 80)); painter.drawText(shadowR, textFlags, ellidedBuildConfiguration); painter.setPen(penColor); } if (!icon().isNull()) { painter.drawText(r, textFlags, ellidedBuildConfiguration); QStyleOption opt; opt.initFrom(this); opt.rect = rect().adjusted(rect().width() - 16, 0, -8, 0); Utils::StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, &painter, &opt); } } else { iconRect.moveCenter(rect().center()); Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled); } }
int main(int argc, char **argv) { QApplication a(argc, argv); a.setApplicationName("QFaktury"); a.setOrganizationName("www.e-linux.pl"); DatabaseManager test; if (test.openDB()) qDebug() << "openned"; else qDebug() << "failed to open"; qDebug() << test.getTables(); test.createTables(); // multilangage a.installTranslator(sett().getTranslation()); QResource::registerResource("qfaktury.rcc"); // using the rcc file so it's more portable // Q_INIT_RESOURCE(qfaktury); QRect screen = QApplication::desktop()->screenGeometry(); QSplashScreen splash(QPixmap(":/res/icons/splash.png")); MainWindow w(0); w.move(screen.center() - QPoint(w.width() / 2, w.height() / 2)); w.show(); #if 1 old_MainWindow old_w(0); old_w.move(screen.center() - QPoint(old_w.width() / 2, old_w.height() / 2)); old_w.show(); #endif a.connect(&w, SIGNAL(closingWindow), &old_w, SLOT(close)); //if (a.arguments().contains("--nosplash")) { /*} else { splash.show(); a.processEvents(); QTimer::singleShot(5000, &w, SLOT(show())); QTimer::singleShot(4960, &splash, SLOT(close())); }*/ a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); QIcon icon; icon.addPixmap(QPixmap(":/res/icons/qfaktury_48.png"), QIcon::Normal, QIcon::Off); a.setWindowIcon(icon); return a.exec(); }
void Style::drawDial(const QStyleOptionComplex *option, QPainter *painter, const QWidget *) const { ASSURE_OPTION(dial, Slider); OPT_ENABLED OPT_HOVER OPT_FOCUS painter->save(); QRect rect = RECT; if (rect.width() > rect.height()) { rect.setLeft(rect.x()+(rect.width()-rect.height())/2); rect.setWidth(rect.height()); } else { rect.setTop(rect.y()+(rect.height()-rect.width())/2); rect.setHeight(rect.width()); } int d = qMin(2*rect.width()/5, Dpi::target.SliderThickness); int r; // angle calculation from qcommonstyle.cpp (c) Trolltech 1992-2007, ASA. float a; if (dial->maximum == dial->minimum) a = M_PI / 2; else if (dial->dialWrapping) a = M_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * M_PI / (dial->maximum - dial->minimum); else a = (M_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * M_PI / (dial->maximum - dial->minimum)) / 6; QPoint cp = rect.center(); // fallback for small dials ============================ bool small(rect.width() < 8*Dpi::target.SliderThickness/3); if ( small ) { painter->setRenderHint( QPainter::Antialiasing ); painter->setPen(Qt::NoPen); painter->setBrush(QColor(0,0,0,50)); painter->drawEllipse(rect); rect.adjust(F(2), F(1), -F(2), -F(2)); painter->setBrushOrigin(rect.topLeft()); const QPixmap &fill = Gradients::pix(FCOLOR(Window), rect.height(), Qt::Vertical, GRAD(scroll)); painter->setBrush(fill); painter->drawEllipse(rect); QColor c = hasFocus ? FCOLOR(Highlight) : FCOLOR(WindowText); if (!hover) c = Colors::mid(FCOLOR(Window), c, 1, 1+isEnabled); d = qMax(F(3), d/4); r = (rect.width()-d)/2; cp += QPoint((int)(r * cos(a)), -(int)(r * sin(a))); painter->setPen(QPen(c, d, Qt::SolidLine, Qt::RoundCap)); painter->drawPoint(cp); } // the value ============================================== QFont fnt = painter->font(); int h = rect.height()/2; h -= 2 * (h - qMin(h, painter->fontMetrics().xHeight())) / 3; fnt.setPixelSize( h ); painter->setFont(fnt); painter->setBrush(Qt::NoBrush); painter->setPen(Colors::mid(PAL.background().color(), PAL.foreground().color(),!hasFocus,2)); drawItemText(painter, rect, Qt::AlignCenter, PAL, isEnabled, QString::number(dial->sliderValue)); if (small) { painter->restore(); return; } r = (rect.width()-d)/2; cp += QPoint((int)(r * cos(a)), -(int)(r * sin(a))); // the huge ring ======================================= r = d/2; rect.adjust(r,r,-r,-r); painter->setPen(FCOLOR(Window).dark(115)); painter->setRenderHint( QPainter::Antialiasing ); painter->drawEllipse(rect); rect.translate(0, 1); painter->setPen(FCOLOR(Window).light(108)); painter->drawEllipse(rect); // the drop =========================== rect = QRect(0,0,d,d); rect.moveCenter(cp); drawSliderHandle(rect, option, painter, hover * 6); painter->restore(); }
void TabBarWidgetMacStyle::tabLayout(const QStyleOptionTab *pOption, const QWidget *pWidget, QRect *pTextRect, QRect *pIconRect) const { // Compute our tab layout // Note: adapted from QCommonStylePrivate::tabLayout()... Q_ASSERT(pTextRect); Q_ASSERT(pIconRect); QRect textRect = pOption->rect; bool verticalTab = (pOption->shape == QTabBar::RoundedWest) || (pOption->shape == QTabBar::RoundedEast) || (pOption->shape == QTabBar::TriangularWest) || (pOption->shape == QTabBar::TriangularEast); if (verticalTab) { textRect.setRect(0, 0, textRect.height(), textRect.width()); } if (!pOption->leftButtonSize.isEmpty()) { textRect.adjust(-4, 0, 0, 0); } int horizontalShift = pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, pOption, pWidget); int verticalShift = pixelMetric(QStyle::PM_TabBarTabShiftVertical, pOption, pWidget); int horizontalPadding = pixelMetric(QStyle::PM_TabBarTabHSpace, pOption, pWidget)/2; int verticalPadding = pixelMetric(QStyle::PM_TabBarTabVSpace, pOption, pWidget)/2; if ( (pOption->shape == QTabBar::RoundedSouth) || (pOption->shape == QTabBar::TriangularSouth)) { verticalShift = -verticalShift; } textRect.adjust(horizontalPadding, verticalShift-verticalPadding, horizontalShift-horizontalPadding, verticalPadding); if ((pOption->state & QStyle::State_Selected) != 0) { textRect.setTop(textRect.top()-verticalShift); textRect.setRight(textRect.right()-horizontalShift); } if (!pOption->leftButtonSize.isEmpty()) { textRect.setLeft( textRect.left() +(verticalTab? pOption->leftButtonSize.height(): pOption->leftButtonSize.width())); } if (!pOption->rightButtonSize.isEmpty()) { textRect.setRight( textRect.right() -(verticalTab? pOption->rightButtonSize.height(): pOption->rightButtonSize.width())); } if (!pOption->icon.isNull()) { QSize iconSize = pOption->iconSize; if (!iconSize.isValid()) { int iconExtent = pixelMetric(QStyle::PM_SmallIconSize); iconSize = QSize(iconExtent, iconExtent); } QSize tabIconSize = pOption->icon.actualSize(iconSize, ((pOption->state & QStyle::State_Enabled) != 0)? QIcon::Normal: QIcon::Disabled, ((pOption->state & QStyle::State_Selected) != 0)? QIcon::On: QIcon::Off); tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); *pIconRect = QRect(textRect.left(), textRect.center().y()-tabIconSize.height()/2, tabIconSize.width(), tabIconSize.height()); if (!verticalTab) { *pIconRect = visualRect(pOption->direction, pOption->rect, *pIconRect); } textRect.setLeft(textRect.left()+tabIconSize.width()+4); } if (!verticalTab) { textRect = visualRect(pOption->direction, pOption->rect, textRect); } *pTextRect = textRect; }