Example #1
0
void ProgressWidget::paintEvent( QPaintEvent * e )
{
    if ( m_progressPercentage < 0.0 )
        return;

    // find out the 'fill' and the 'clear' rectangles
    int w = width(),
        h = height(),
        l = (int)( (float)w * m_progressPercentage );
    QRect cRect = ( QApplication::reverseLayout() ? QRect( 0, 0, w - l, h ) : QRect( l, 0, w - l, h ) ).intersect( e->rect() );
    QRect fRect = ( QApplication::reverseLayout() ? QRect( w - l, 0, l, h ) : QRect( 0, 0, l, h ) ).intersect( e->rect() );

    // paint rects and a separator line
    QPainter p( this );
    if ( cRect.isValid() )
        p.fillRect( cRect, palette().active().highlightedText() );
    if ( fRect.isValid() )
        p.fillRect( fRect, palette().active().highlight() );
    if ( l && l != w  )
    {
        p.setPen( palette().active().highlight().dark( 120 ) );
        int delta = QApplication::reverseLayout() ? w - l : l;
        p.drawLine( delta, 0, delta, h );
    }
    // draw a frame-like outline
    //p.setPen( palette().active().mid() );
    //p.drawRect( 0,0, w, h );
}
static QRect relativeRect(const QStyleOption& option,
						  const QSize &size,
						  const QRect& prevRect,
						  int padding = 0)
{
	QRect r = option.rect;
	const bool isRTL = option.direction == Qt::RightToLeft;
	if (isRTL) {
		if (prevRect.isValid())
			r.setRight(prevRect.left() - padding);
		if (size.isValid()) {
			r.setLeft(r.right() - size.width() + 1);
			r.setBottom(r.top() + size.height() - 1);
			r.translate(-1, 1);
		}
	} else {
		if (prevRect.isValid())
			r.setLeft(prevRect.right() + padding);
		if (size.isValid()) {
			r.setSize(size);
			r.translate(1, 1);
		}
	}
	return r;
}
Example #3
0
/**
 * Displays a tool-tip according to the current location of the mouse
 * pointer.
 * @param	pt	The mouse pointer coordinates
 */
void ListToolTip::maybeTip(const QPoint& pt)
{
	QString str;
	QListView* pList;
	QListViewItem* pItem;
	
	// Get the item at the given point
	pList = m_pList->getList();
	pItem = pList->itemAt(pt);
	if (pItem == NULL)
		return;

	// Get the tip string for this item
	if (!m_pList->getTip(pItem, str))
		return;

	// Get the bounding rectangle of the item
	const QRect rcItem = pList->itemRect(pItem);
	if (!rcItem.isValid())
		return;

	// Get the header coordinates
	const QRect rcHead = pList->header()->rect();
	if (!rcHead.isValid())
		return;

	// Calculate the tool-tip rectangle
	QRect rcCell(rcHead.left(), rcItem.top(), rcItem.width(), rcItem.height());

	// Display the tool-tip
	tip(rcCell, str);
}
void QtnPropertyDelegateQFont::drawValueImpl(QStylePainter& painter, const QRect& rect, const QStyle::State& state, bool* needTooltip) const
{
    QFont value = owner().value();

    QRect textRect = rect;

    if (textRect.isValid())
    {
        QRect br;

        QFont oldFont = painter.font();
        QFont newFont(value);
        newFont.setPointSize(oldFont.pointSize());
        painter.setFont(newFont);
        painter.drawText(textRect, Qt::AlignLeading | Qt::AlignVCenter, "A", &br);
        painter.setFont(oldFont);

        textRect.setLeft(br.right() + 3);
    }

    if (textRect.isValid())
    {
        QtnPropertyDelegateTypedEx<QtnPropertyQFontBase>::drawValueImpl(painter, textRect, state, needTooltip);
    }
}
Example #5
0
/*!
    Wrapper for QPainter::fillRect()
*/
void QwtPainter::fillRect(QPainter *painter,
    const QRect &rect, const QBrush &brush)
{
    if ( !rect.isValid() )
        return;

    QRect clipRect;
    const bool deviceClipping = isClippingNeeded(painter, clipRect);

#if QT_VERSION >= 0x040000
    /*
      Performance of Qt4 is horrible for non trivial brushs. Without
      clipping expect minutes or hours for repainting large rects
      (might result from zooming)
    */

    if ( deviceClipping )
        clipRect &= painter->window();
    else
        clipRect = painter->window();

    if ( painter->hasClipping() )
        clipRect &= painter->clipRegion().boundingRect();
#endif

    QRect r = d_metricsMap.layoutToDevice(rect, painter);
    if ( deviceClipping )
        r = r.intersect(clipRect);

    if ( r.isValid() )
        painter->fillRect(r, brush);
}
Example #6
0
/****************************************************************************
  Hacks to glue AGL to an HIView
  ***************************************************************************/
QRegion qt_mac_get_widget_rgn(const QWidget *widget)
{
    if(!widget->isVisible() || widget->isMinimized())
        return QRegion();
    const QRect wrect = QRect(qt_mac_posInWindow(widget), widget->size());
    if(!wrect.isValid())
        return QRegion();

    RgnHandle macr = qt_mac_get_rgn();
    GetControlRegion((HIViewRef)widget->winId(), kControlStructureMetaPart, macr);
    OffsetRgn(macr, wrect.x(), wrect.y());
    QRegion ret = qt_mac_convert_mac_region(macr);

    QPoint clip_pos = wrect.topLeft();
    for(const QWidget *last_clip = 0, *clip = widget; clip; last_clip = clip, clip = clip->parentWidget()) {
        if(clip != widget) {
            GetControlRegion((HIViewRef)clip->winId(), kControlStructureMetaPart, macr);
            OffsetRgn(macr, clip_pos.x(), clip_pos.y());
            ret &= qt_mac_convert_mac_region(macr);
        }
        const QObjectList &children = clip->children();
        for(int i = children.size()-1; i >= 0; --i) {
            if(QWidget *child = qobject_cast<QWidget*>(children.at(i))) {
                if(child == last_clip)
                    break;

                // This check may seem weird, but when we are using a unified toolbar
                // The widget is actually being owned by that toolbar and not by Qt.
                // This means that the geometry it reports will be wrong
                // and will accidentally cause problems when calculating the region
                // So, it is better to skip these widgets since they aren't the hierarchy
                // anyway.
                if (HIViewGetSuperview(HIViewRef(child->winId())) != HIViewRef(clip->winId()))
                    continue;

                if(child->isVisible() && !child->isMinimized() && !child->isTopLevel()) {
                    const QRect childRect = QRect(clip_pos+child->pos(), child->size());
                    if(childRect.isValid() && wrect.intersects(childRect)) {
                        GetControlRegion((HIViewRef)child->winId(), kControlStructureMetaPart, macr);
                        OffsetRgn(macr, childRect.x(), childRect.y());
                        ret -= qt_mac_convert_mac_region(macr);
                    }
                }
            }
        }
        if(clip->isWindow())
            break;
        clip_pos -= clip->pos();
    }
    qt_mac_dispose_rgn(macr);
    return ret;
}
Example #7
0
// Store normal geometry used for saving application settings.
void QWidgetWindow::updateNormalGeometry()
{
    QTLWExtra *tle = m_widget->d_func()->maybeTopData();
    if (!tle)
        return;
     // Ask platform window, default to widget geometry.
    QRect normalGeometry;
    if (const QPlatformWindow *pw = handle())
        normalGeometry = pw->normalGeometry();
    if (!normalGeometry.isValid() && effectiveState(m_widget->windowState()) == Qt::WindowNoState)
        normalGeometry = m_widget->geometry();
    if (normalGeometry.isValid())
        tle->normalGeometry = normalGeometry;
}
Example #8
0
bool ToolTip::eventFilter(QObject* watched, QEvent* event)
{
    if ((watched == parent()) && (event->type() == QEvent::ToolTip))
    {
        const QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);

        QRect rect;
        QString text;
        emit queryToolTip(helpEvent->pos(), rect, text);

        if (rect.isValid() && !text.isEmpty())
        {
            QWidget* parentWidget = static_cast<QWidget*>(parent());
            text = truncateLines(text,
                                 QToolTip::font(),
                                 helpEvent->globalPos(),
                                 KGlobalSettings::desktopGeometry(parentWidget));
            QToolTip::showText(helpEvent->globalPos(), text, parentWidget, rect);
        }

        return true;
    }

    return QObject::eventFilter(watched, event);
}
Example #9
0
void ExpandingTree::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
  QTreeView::drawRow( painter, option, index );

  const ExpandingWidgetModel* eModel = qobject_cast<const ExpandingWidgetModel*>(model());
  if( eModel && eModel->isPartiallyExpanded( index ) )
  {
    QRect rect = eModel->partialExpandRect( index );
    if( rect.isValid() )
    {
      painter->fillRect(rect,QBrush(0xffffffff));

      QAbstractTextDocumentLayout::PaintContext ctx;
      // since arbitrary HTML can be shown use a black on white color scheme here
      ctx.palette = QPalette( Qt::black, Qt::white );
      ctx.clip = QRectF(0,0,rect.width(),rect.height());;
      painter->setViewTransformEnabled(true);
      painter->translate(rect.left(), rect.top());

      m_drawText.setHtml( eModel->partialExpandText( index ) );
      m_drawText.setPageSize(QSizeF(rect.width(), rect.height()));
      m_drawText.documentLayout()->draw( painter, ctx );

      painter->translate(-rect.left(), -rect.top());
    }
  }
}
Example #10
0
void CacheItem::validateCacheView(const GuiContext& ctx, const QRect* visibleRect)
{
    if (m_isCacheViewValid)
        return;

    Q_ASSERT(!m_cacheView);

    QRect* visibleItemRectPtr = nullptr;

    QRect visibleItemRect;
    if (visibleRect)
    {
        visibleItemRect = rect.intersected(*visibleRect);
        if (visibleItemRect.isValid() && visibleItemRect != rect)
        {
            // only apply if visibleCellRect partly intersects cellRect
            visibleItemRectPtr = &visibleItemRect;
        }
    }

    if (schema.isValid())
    {
        QRect itemRect = rect;
        QVector<CacheView2> cacheViews;
        CacheView2* cacheView = schema.view->addCacheView(*schema.layout, ctx, id, cacheViews, itemRect, visibleItemRectPtr);
        if (cacheView)
        {
            m_cacheView.reset(new CacheView2(*cacheView));
        }
    }

    // mark cache views as valid
    m_isCacheViewValid = true;
}
Example #11
0
void ColourBrush::endCapture()
{
    if (mBrushBehavior != Capture)
        return;

    mBrushBehavior = Free;

    ColourLayer *colourLayer = currentColourLayer();
    Q_ASSERT(colourLayer);

    // Intersect with the layer and translate to layer coordinates
    QRect captured = capturedArea();
    captured.intersect(QRect(colourLayer->x(), colourLayer->y(),
                             colourLayer->width(), colourLayer->height()));

    if (captured.isValid()) {
        captured.translate(-colourLayer->x(), -colourLayer->y());
        ColourLayer *capture = colourLayer->copy(captured);
        emit currentTilesChanged(capture);
        // A copy will have been created, so delete this version
        delete capture;
    } else {
        updatePosition();
    }
}
Example #12
0
MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags), ui(new Ui::MainWindow)
{
	//qDebug() << "setup ui";
	ui->setupUi(this);
	setWindowTitle("QSIClient");
	//qDebug() << "setup ui OK";
	connect(theApp(), SIGNAL(logRequest(int,QString)), this, SLOT(appendLog(int,QString)));
	//connect(theApp(), SIGNAL(logRequestPre(int,QString)), this, SLOT(appendLogPre(int,QString)));

	connect(ui->actCommOpen, &QAction::toggled, this, &MainWindow::onCommOpen);
	connect(ui->actSqlConnect, &QAction::toggled, theApp(), &TheApp::connectSql);
	connect(ui->actConfig, &QAction::triggered, this, &MainWindow::actConfigTriggered);
	connect(ui->actHelpAbout, &QAction::triggered, this, &MainWindow::onHelpAbout);
	connect(ui->actHelpAboutQt, &QAction::triggered, this, &MainWindow::onHelpAboutQt);
	{
		siut::DeviceDriver *drv = theApp()->siDriver();
		connect(drv, &siut::DeviceDriver::driverInfo, this, &MainWindow::processDriverInfo, Qt::QueuedConnection);
		connect(drv, &siut::DeviceDriver::messageReady, this, &MainWindow::processSIMessage, Qt::QueuedConnection);
		connect(drv, &siut::DeviceDriver::rawDataReceived, this, &MainWindow::processDriverRawData, Qt::QueuedConnection);
		connect(this, &MainWindow::sendSICommand, drv, &siut::DeviceDriver::sendCommand, Qt::QueuedConnection);
	}
	{
		QSettings settings;
		QRect r = settings.value("mainWindow/geometry").toRect();
		if(r.isValid()) setGeometry(r);
	}
}
Example #13
0
LogWindow::LogWindow()
    : QWidget( 0, Qt::Tool|Qt::WindowStaysOnTopHint )
{
    setWindowTitle( tr("Qtopia Sync Agent Messages") );

    DesktopSettings settings( "logwindow" );
    QRect r = settings.value( "geometry" ).toRect();
    if ( r.isValid() )
        setGeometry( r );

    textView = new QTextEdit;
    textView->setReadOnly( true );
    textView->setLineWrapMode( QTextEdit::NoWrap );
    textView->clear();

    QHBoxLayout *hbox = new QHBoxLayout( this );
    hbox->setMargin( 0 );
    hbox->setSpacing( 0 );

    hbox->addWidget( textView );

    QCopChannel *status = new QCopChannel( "QD/Status", this );
    connect( status, SIGNAL(received(QString,QByteArray)),
            this, SLOT(statusMessage(QString,QByteArray)) );
    QCopChannel *sys = new QCopChannel( "QD/Connection", this );
    connect( sys, SIGNAL(received(QString,QByteArray)), this, SLOT(connectionMessage(QString,QByteArray)) );
}
Example #14
0
void SceneBorder::render(QPainter * painter, const QRect & rect)
{
    if (rect.isValid())
    {
        painter->drawImage(rect, m_temp_image, m_rect);
    }
}
Example #15
0
void QFrame::setFrameRect(const QRect &r)
{
    Q_D(QFrame);
    QRect cr = r.isValid() ? r : rect();
    cr.adjust(d->leftFrameWidth, d->topFrameWidth, -d->rightFrameWidth, -d->bottomFrameWidth);
    setContentsMargins(cr.left(), cr.top(), rect().right() - cr.right(), rect().bottom() - cr.bottom());
}
void Layer_list_delegate::drawCheck(QPainter *painter,
                              const QStyleOptionViewItem &option,
							  const QRect &rect, Qt::CheckState state) const {
    if (!rect.isValid())
        return;

    QStyleOptionViewItem opt(option);
    opt.rect = rect;
    opt.state = opt.state & ~QStyle::State_HasFocus;

    switch (state) {
    case Qt::Unchecked:
        opt.state |= QStyle::State_Off;
        break;
    case Qt::PartiallyChecked:
        opt.state |= QStyle::State_NoChange;
        break;
    case Qt::Checked:
        opt.state |= QStyle::State_On;
        break;
    }

	// paint background
	if (state == Qt::Checked) {
		// create the rectangle we want to paint
		QRect dec;
		#ifdef Q_WS_WIN
		dec = rect.translated(-2,-2);
		dec.setWidth(dec.width()+3);
		dec.setHeight(dec.height()+3);
		#else
		dec = rect.translated(-2,-2);
		//dec.setWidth(dec.width()-1);
		//dec.setHeight(dec.height()-1);
		#endif //Q_WS_WIN


		// paint the background rectangle
		QPointF oldBO = painter->brushOrigin();
		painter->setBrushOrigin(dec.topLeft());
		QColor background_color = opt.palette.brush(QPalette::LinkVisited).color();
		painter->fillRect(dec, opt.palette.brush(QPalette::LinkVisited));

		//set the font color so that one can see it on the background
		if (background_color.red() > 128 || background_color.green() > 128 || background_color.alpha() < 128)
			opt.palette.setColor(QPalette::Text, Qt::black);
		else opt.palette.setColor(QPalette::Text, Qt::white);
		// set back the brush origin to the original place
		painter->setBrushOrigin(oldBO);
	}
	
//	#ifdef Q_WS_WIN
	QWindowsStyle windows_style;
	windows_style.drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter);
//	#else
//	QApplication::style()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter);
//	#endif //Q_WS_WIN


}
Example #17
0
void XRandRScreens::update()
{
    auto fallback = [this]() {
        m_geometries << QRect();
        setCount(1);
    };
    m_geometries.clear();
    T resources(rootWindow());
    if (resources.isNull()) {
        fallback();
        return;
    }
    xcb_randr_crtc_t *crtcs = resources.crtcs();

    QVector<Xcb::RandR::CrtcInfo> infos(resources->num_crtcs);
    for (int i = 0; i < resources->num_crtcs; ++i) {
        infos[i] = Xcb::RandR::CrtcInfo(crtcs[i], resources->config_timestamp);
    }
    for (int i = 0; i < resources->num_crtcs; ++i) {
        Xcb::RandR::CrtcInfo info(infos.at(i));
        const QRect geo = info.rect();
        if (geo.isValid()) {
            m_geometries << geo;
        }
    }
    if (m_geometries.isEmpty()) {
        fallback();
        return;
    }

    setCount(m_geometries.count());
}
Example #18
0
 void paintSection( QPainter * painter, const QRect& rect, int logicalIndex ) const override {
     
     if ( rect.isValid() ) {
         if ( logicalIndex > 0 ) {
             QStyleOptionHeader op;
             initStyleOption(&op);
             op.text = "";
             op.rect = rect;
             op.textAlignment = Qt::AlignVCenter | Qt::AlignHCenter;
             // draw the section
             style()->drawControl( QStyle::CE_Header, &op, painter, this );
             // html painting
             painter->save();
             QRect textRect = style()->subElementRect( QStyle::SE_HeaderLabel, &op, this );
             painter->translate( textRect.topLeft() );
             QTextDocument doc;
             doc.setTextWidth( textRect.width() );
             doc.setDefaultTextOption( QTextOption( Qt::AlignHCenter ) );
             doc.setDocumentMargin(0);
             doc.setHtml( model()->headerData( logicalIndex, Qt::Horizontal ).toString() );
             doc.drawContents( painter, QRect( QPoint( 0, 0 ), textRect.size() ) );
             painter->restore();
         } else {
             QHeaderView::paintSection( painter, rect, logicalIndex );
         }
     }
 }
Example #19
0
void IconDelegate::drawCheck(QPainter *painter,
                              const QStyleOptionViewItem &option,
                              const QRect &rect, Qt::CheckState state) const
{
    if (!rect.isValid())
        return;

    QStyleOptionViewItem opt;
    opt.QStyleOption::operator=(option);
    opt.rect = rect;
    opt.state = opt.state & ~QStyle::State_HasFocus;

    switch (state) {
    case Qt::Unchecked:
        opt.state |= QStyle::State_Off;
        break;
    case Qt::PartiallyChecked:
        opt.state |= QStyle::State_NoChange;
        break;
    case Qt::Checked:
        opt.state |= QStyle::State_On;
        break;
    }

    QApplication::style()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter);
}
    //________________________________________________
    QPixmap TransitionWidget::grab( QWidget* widget, QRect rect )
    {

        // change rect
        if( !rect.isValid() ) rect = widget->rect();
        if( !rect.isValid() ) return QPixmap();

        // initialize pixmap
        QPixmap out( rect.size() );
        out.fill( Qt::transparent );
        _paintEnabled = false;

        if( testFlag( GrabFromWindow ) )
        {

            rect = rect.translated( widget->mapTo( widget->window(), widget->rect().topLeft() ) );
            widget = widget->window();
            #if QT_VERSION < 0x050000
            out = QPixmap::grabWidget( widget, rect );
            #else
            out = widget->grab( rect );
            #endif

        } else {

            if( !testFlag( Transparent ) ) { grabBackground( out, widget, rect ); }
            grabWidget( out, widget, rect );

        }

        _paintEnabled = true;

        return out;

    }
Example #21
0
void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate)
{
    QRect r = widget->geometry();
    if (r.right() < 0 || r.bottom() < 0)
        r = QRect();

    animate = animate && !r.isNull() && !_final_geometry.isNull();

    // might make the wigdet go away by sending it to negative space
    const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
        QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());

#ifndef QT_NO_ANIMATION
    AnimationMap::const_iterator it = m_animation_map.constFind(widget);
    if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
        return;

    QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
    anim->setDuration(animate ? 200 : 0);
    anim->setEasingCurve(QEasingCurve::InOutQuad);
    anim->setEndValue(final_geometry);
    m_animation_map[widget] = anim;
    connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
    anim->start(QPropertyAnimation::DeleteWhenStopped);
#else
    //we do it in one shot
    widget->setGeometry(final_geometry);
#ifndef QT_NO_MAINWINDOW
    m_mainWindowLayout->animationFinished(widget);
#endif //QT_NO_MAINWINDOW
#endif //QT_NO_ANIMATION
}
Example #22
0
void KoTabBar::mouseMoveEvent( QMouseEvent* ev )
{
    if ( d->readOnly ) return;

    QPoint pos = ev->pos();
    if( !d->reverseLayout) pos = pos - QPoint( d->offset,0 );
    
    // check if user drags a tab to move it
    int i = d->tabAt( pos ) + 1;
    if( ( i > 0 ) && ( i != d->targetTab ) )
    {
        if( i == d->activeTab ) i = 0;
        if( i == d->activeTab+1 ) i = 0;

        if( i != d->targetTab )
        {
           d->targetTab = i;
           d->autoScroll = false;
           update();
        }
    }

    // drag past the very latest visible tab
    // e.g move a tab to the last ordering position
    QRect r = d->tabRects[ d->tabRects.count()-1 ];
    bool moveToLast = false;
    if( r.isValid() )
    {
        if( !d->reverseLayout )
        if( pos.x() > r.right() )
        if( pos.x() < width() )
            moveToLast = true;
        if( d->reverseLayout )
        if( pos.x() < r.x() )
        if( pos.x() > 0 )
            moveToLast = true;
    }
    if( moveToLast )
    if( d->targetTab != (int)d->tabRects.count()+1 )
    {
        d->targetTab = d->tabRects.count()+1;
        d->autoScroll = false;
        update();
    }

    // outside far too left ? activate autoscroll...
    if ( pos.x() < 0 && !d->autoScroll  )
    {
        d->autoScroll = true;
        autoScrollBack();
    }

    // outside far too right ? activate autoscroll...
    int w = width() - d->offset;
    if ( pos.x() > w && !d->autoScroll )
    {
        d->autoScroll = true;
        autoScrollForward();
    }
}
Example #23
0
void Portal::set_geometry( QRect rect ) {
   if( rect.isNull() ) {
      rect = this->default_geometry();
      
      QString val;

      val = Config::main()->get( "portal::geometry::left" );
      if( !val.isNull() ) 
	 rect.setLeft( val.toInt() );
      val = Config::main()->get( "portal::geometry::right" );
      if( !val.isNull() ) 
	 rect.setRight( val.toInt() );
      val = Config::main()->get( "portal::geometry::top" );
      if( !val.isNull() ) 
	 rect.setTop( val.toInt() );
      val = Config::main()->get( "portal::geometry::bottom" );
      if( !val.isNull() ) 
	 rect.setBottom( val.toInt() );
   }

   if( !rect.isValid() )
      rect = this->default_geometry();

   this->setGeometry( rect );
}
void VirtualKeyboardContainer::showVirtualKeyboard(QWidget *w)
{
    if ( w )
    {       
        QPoint pg(w->mapToGlobal( QPoint( 0, 0 ) ) );
        QPoint pd(parent->mapFromGlobal( pg ) );

        int origin = pd.y();
        int keyboardWidth = parent->width() - 10;
        int keyboardHeight = std::min(vk.heightForWidth( keyboardWidth ), parent->height() - w->height() - 5);

        QRect kRect;
        if ( origin + w->height() + keyboardHeight <= parent->height() )
        {
            // keyboard can be placed below the widget
            kRect = QRect( 0, origin + w->height(), keyboardWidth, keyboardHeight );
        }
        else
        if ( origin - keyboardHeight >= 0 )
        {
            // keyboard can be placed above the widget
            kRect = QRect( 0, origin - keyboardHeight, keyboardWidth, keyboardHeight );
        }
        else
        {
            // we need to resize the dialog to place the keyboard below the widget
            int remainHeight = parent->height() - origin - w->height();
            extraSize = keyboardHeight - remainHeight;
            QPoint p(parent->pos());
            parent->move( p.x(), p.y() - extraSize );
            QSize s(parent->size());
            parent->resize( s.width(), s.height() + extraSize );
            kRect = QRect( 0, origin + w->height(), keyboardWidth, keyboardHeight );
        }

        if ( kRect.isValid() )
        {
            vk.setGeometry( kRect );
            vk.raise();
            vk.show();
        }
        else
        {
            vk.hide();
        }
    }
    else
    {
        if ( extraSize > 0 )
        {
            QPoint p(parent->pos());
            parent->move( p.x(), p.y() + extraSize );
            QSize s(parent->size());
            parent->resize( s.width(), s.height() - extraSize );
            extraSize = 0;
        }
        vk.hide();
    }
    vk.setBuddy(w);
}
Example #25
0
void QItemDelegate::drawCheck(QPainter *painter,
                              const QStyleOptionViewItem &option,
                              const QRect &rect, Qt::CheckState state) const
{
    Q_D(const QItemDelegate);
    if (!rect.isValid())
        return;

    QStyleOptionViewItem opt(option);
    opt.rect = rect;
    opt.state = opt.state & ~QStyle::State_HasFocus;

    switch (state) {
    case Qt::Unchecked:
        opt.state |= QStyle::State_Off;
        break;
    case Qt::PartiallyChecked:
        opt.state |= QStyle::State_NoChange;
        break;
    case Qt::Checked:
        opt.state |= QStyle::State_On;
        break;
    }

    const QWidget *widget = d->widget(option);
    QStyle *style = widget ? widget->style() : QApplication::style();
    style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter, widget);
}
Example #26
0
void StampBrush::endCapture()
{
    if (mBrushBehavior != Capture)
        return;

    mBrushBehavior = Free;

    TileLayer *tileLayer = currentTileLayer();
    Q_ASSERT(tileLayer);

    // Intersect with the layer and translate to layer coordinates
    QRect captured = capturedArea();
    captured &= QRect(tileLayer->x(), tileLayer->y(),
                      tileLayer->width(), tileLayer->height());

    if (captured.isValid()) {
        captured.translate(-tileLayer->x(), -tileLayer->y());
        Map *map = tileLayer->map();
        TileLayer *capture = tileLayer->copy(captured);
        Map *stamp = new Map(map->orientation(),
                             capture->width(),
                             capture->height(),
                             map->tileWidth(),
                             map->tileHeight());

        // Add tileset references to map
        foreach (const SharedTileset &tileset, capture->usedTilesets())
            stamp->addTileset(tileset);

        stamp->addLayer(capture);

        emit stampCaptured(TileStamp(stamp));
    } else {
void IconsetDelegate::drawCheckButton(QPainter *APainter, const QStyleOptionViewItemV4 &AIndexOption, const QRect &ARect, Qt::CheckState AState) const
{
	if (ARect.isValid())
	{
		QStyleOptionViewItem checkOption(AIndexOption);
		checkOption.rect = ARect;
		checkOption.state = checkOption.state & ~QStyle::State_HasFocus;

		switch (AState)
		{
		case Qt::Unchecked:
			checkOption.state |= QStyle::State_Off;
			break;
		case Qt::PartiallyChecked:
			checkOption.state |= QStyle::State_NoChange;
			break;
		case Qt::Checked:
			checkOption.state |= QStyle::State_On;
			break;
		}

		const QStyle *style = AIndexOption.widget ? AIndexOption.widget->style()->proxy() : QApplication::style()->proxy();
		style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkOption, APainter, AIndexOption.widget);
	}
}
Example #28
0
void TupLayerIndexHeader::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
    if (!rect.isValid())
        return;

    QStyleOptionHeader headerOption;
    headerOption.rect = rect;
    headerOption.orientation = Qt::Horizontal;
    headerOption.position = QStyleOptionHeader::Middle;

    QStyle::State state = QStyle::State_None;

    if (isEnabled())
        state |= QStyle::State_Enabled;

    if (window()->isActiveWindow())
        state |= QStyle::State_Active;

    style()->drawControl(QStyle::CE_HeaderSection, &headerOption, painter);

    //painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1));

    QString text = model()->headerData(logicalIndex, orientation(), Qt::DisplayRole).toString();;

    //QFontMetrics fm(painter->font());
    QFont label("Arial", 9, QFont::Bold, false);
    QFontMetrics fm(label);

    int x = rect.x() + (sectionSize(logicalIndex) - fm.width( text ))/2;
    //int y = fm.height() + (rect.y() / 2);
    int y = 17;
    painter->setFont(label);
    painter->drawText(x, y, text);
}
void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut)
{
    if (!sys || !sys->allowsMessages())
        return;

    uint uSecs = 0;
    if ( timeOut < 0)
        uSecs = 10000; //10 sec default
    else uSecs = (int)timeOut;

    //message is limited to 255 chars + NULL
    QString messageString;
    if (message.isEmpty() && !title.isEmpty())
        messageString = QLatin1Char(' '); //ensures that the message shows when only title is set
    else
        messageString = message.left(255) + QChar();

    //title is limited to 63 chars + NULL
    QString titleString = title.left(63) + QChar();

    if (sys->supportsMessages()) {
        sys->showMessage(titleString, messageString, type, (unsigned int)uSecs);
    } else {
        //use fallback
        QRect iconPos = sys->findIconGeometry(q_uNOTIFYICONID);
        if (iconPos.isValid()) {
            QBalloonTip::showBalloon(type, title, message, sys->q, iconPos.center(), uSecs, true);
        }
    }
}
Example #30
0
Flipbook::Flipbook(QWidget *parent)
	: QDialog(parent), m_ui(new Ui_Flipbook), m_layers(nullptr)
{
	m_ui->setupUi(this);

	m_timer = new QTimer(this);

	connect(m_ui->rewindButton, &QToolButton::clicked, this, &Flipbook::rewind);
	connect(m_ui->playButton, &QToolButton::clicked, this, &Flipbook::playPause);
	connect(m_ui->layerIndex, QOverload<int>::of(&QSpinBox::valueChanged), this, &Flipbook::loadFrame);
	connect(m_ui->loopStart, QOverload<int>::of(&QSpinBox::valueChanged), this, &Flipbook::updateRange);
	connect(m_ui->loopEnd, QOverload<int>::of(&QSpinBox::valueChanged), this, &Flipbook::updateRange);
	connect(m_ui->fps, QOverload<int>::of(&QSpinBox::valueChanged), this, &Flipbook::updateFps);
	connect(m_timer, &QTimer::timeout, m_ui->layerIndex, &QSpinBox::stepUp);
	connect(m_ui->view, &FlipbookView::cropped, this, &Flipbook::setCrop);
	connect(m_ui->zoomButton, &QToolButton::clicked, this, &Flipbook::resetCrop);

	updateRange();

	m_ui->playButton->setFocus();

	// Load default settings
	QSettings cfg;
	cfg.beginGroup("flipbook");

	m_ui->fps->setValue(cfg.value("fps", 15).toInt());

	QRect geom = cfg.value("window", QRect()).toRect();
	if(geom.isValid()) {
		setGeometry(geom);
	}

	// Autoplay
	m_ui->playButton->click();
}