Exemple #1
0
void MyWindow::setWidth(int arg)
{
    if (m_width != arg&&arg<=maximumWidth ()&&arg>=minimumWidth ()) {
        m_width = arg;
        contentItem ()->setWidth (arg);
        emit widthChanged(arg);
    }
}
Exemple #2
0
bool KWidget::widthToChild()
{
    qreal minwidth = minimumWidth();
    qreal maxwidth = maximumWidth();
    if(minwidth == -1.0 && maxwidth == -1.0)
        return true;
    return false;
}
Exemple #3
0
void ItemWeb::updateSize()
{
    const int w = maximumWidth();
    page()->setPreferredContentsSize( QSize(w, 10) );
    QSize size( w, page()->mainFrame()->contentsSize().height() );
    page()->setViewportSize(size);
    resize(size);
}
Exemple #4
0
QSize
ComboBox::sizeForWidth(int w) const
{
    if (minimumWidth() > 0) {
        w = std::max( w, maximumWidth() );
    }
    QSize contentsMargin;
    {
        QMargins margins = contentsMargins();
        contentsMargin.setWidth( margins.left() + margins.right() );
        contentsMargin.setHeight( margins.bottom() + margins.top() );
    }
    QRect br;

    //Using this constructor of QFontMetrics will respect the DPI of the screen, see http://doc.qt.io/qt-4.8/qfontmetrics.html#QFontMetrics-2
    QFontMetrics fm(font(), 0);
    Qt::Alignment align = QStyle::visualAlignment( Qt::LeftToRight, QFlag(_align) );
    int hextra = DROP_DOWN_ICON_SIZE * 2, vextra = 0;

    ///Indent of 1 character
    int indent = fm.width( QLatin1Char('x') );

    if (indent > 0) {
        if ( (align & Qt::AlignLeft) || (align & Qt::AlignRight) ) {
            hextra += indent;
        }
        if ( (align & Qt::AlignTop) || (align & Qt::AlignBottom) ) {
            vextra += indent;
        }
    }
    // Turn off center alignment in order to avoid rounding errors for centering,
    // since centering involves a division by 2. At the end, all we want is the size.
    int flags = align & ~(Qt::AlignVCenter | Qt::AlignHCenter);
    bool tryWidth = (w < 0) && (align & Qt::TextWordWrap);

    if (tryWidth) {
        w = std::min( fm.averageCharWidth() * 80, maximumSize().width() );
    } else if (w < 0) {
        w = 2000;
    }

    w -= ( hextra + contentsMargin.width() );

    br = fm.boundingRect(0, 0, w, 2000, flags, _currentText);

    if ( tryWidth && ( br.height() < 4 * fm.lineSpacing() ) && (br.width() > w / 2) ) {
        br = fm.boundingRect(0, 0, w / 2, 2000, flags, _currentText);
    }

    if ( tryWidth && ( br.height() < 2 * fm.lineSpacing() ) && (br.width() > w / 4) ) {
        br = fm.boundingRect(0, 0, w / 4, 2000, flags, _currentText);
    }

    const QSize contentsSize(br.width() + hextra, br.height() + vextra);

    return (contentsSize + contentsMargin).expandedTo( minimumSize() );
} // ComboBox::sizeForWidth
Exemple #5
0
void WDialog::render(WFlags<RenderFlag> flags)
{
  if (flags & RenderFull) {
    WApplication *app = WApplication::instance();

    bool centerX = offset(Left).isAuto() && offset(Right).isAuto(),
      centerY = offset(Top).isAuto() && offset(Bottom).isAuto();

    /*
     * Make sure layout adjusts to contents preferred width, especially
     * important for IE workaround which uses static position scheme
     */
    if (app->environment().ajax())
      if (width().isAuto())
	if (maximumWidth().unit() == WLength::Percentage ||
	    maximumWidth().toPixels() == 0)
	  impl_->resolveWidget("layout")->setMaximumSize(999999, maximumHeight());

    doJavaScript("new " WT_CLASS ".WDialog("
		 + app->javaScriptClass() + "," + jsRef()
		 + "," + titleBar_->jsRef()
		 + "," + (centerX ? "1" : "0")
		 + "," + (centerY ? "1" : "0") + ");");

    /*
     * When a dialog is shown immediately for a new session, the recentering
     * logic comes too late and causes a glitch. Thus we include directly in
     * the HTML a JavaScript block to mitigate that
     */
    if (!app->environment().agentIsIElt(9)) {
      std::string js = WString::tr("Wt.WDialog.CenterJS").toUTF8();
      Utils::replace(js, "$el", "'" + id() + "'");
      Utils::replace(js, "$centerX", centerX ? "1" : "0");
      Utils::replace(js, "$centerY", centerY ? "1" : "0");

      impl_->bindString
	("center-script", "<script>" + js + "</script>", XHTMLUnsafeText);
    } else
      impl_->bindEmpty("center-script");
  }

  WCompositeWidget::render(flags);
}
void BackgroundWidget::paintEvent( QPaintEvent *e )
{
    if ( !b_withart )
    {
        /* we just want background autofill */
        QWidget::paintEvent( e );
        return;
    }

    int i_maxwidth, i_maxheight;
    QPixmap pixmap = QPixmap( pixmapUrl );
    QPainter painter(this);
    QBitmap pMask;
    float f_alpha = 1.0;

    i_maxwidth  = __MIN( maximumWidth(), width() ) - MARGIN * 2;
    i_maxheight = __MIN( maximumHeight(), height() ) - MARGIN * 2;

    painter.setOpacity( property( "opacity" ).toFloat() );

    if ( height() > MARGIN * 2 )
    {
        /* Scale down the pixmap if the widget is too small */
        if( pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight )
        {
            pixmap = pixmap.scaled( i_maxwidth, i_maxheight,
                            Qt::KeepAspectRatio, Qt::SmoothTransformation );
        }
        else
        if ( b_expandPixmap &&
             pixmap.width() < width() && pixmap.height() < height() )
        {
            /* Scale up the pixmap to fill widget's size */
            f_alpha = ( (float) pixmap.height() / (float) height() );
            pixmap = pixmap.scaled(
                    width() - MARGIN * 2,
                    height() - MARGIN * 2,
                    Qt::KeepAspectRatio,
                    ( f_alpha < .2 )? /* Don't waste cpu when not visible */
                        Qt::SmoothTransformation:
                        Qt::FastTransformation
                    );
            /* Non agressive alpha compositing when sizing up */
            pMask = QBitmap( pixmap.width(), pixmap.height() );
            pMask.fill( QColor::fromRgbF( 1.0, 1.0, 1.0, f_alpha ) );
            pixmap.setMask( pMask );
        }

        painter.drawPixmap(
                MARGIN + ( i_maxwidth - pixmap.width() ) /2,
                MARGIN + ( i_maxheight - pixmap.height() ) /2,
                pixmap);
    }
    QWidget::paintEvent( e );
}
Exemple #7
0
void
ComboBox::growMaximumWidthFromText(const QString & str)
{
    if (_sizePolicy.horizontalPolicy() == QSizePolicy::Fixed) {
        return;
    }
    int w = fontMetrics().width(str) + 2 * DROP_DOWN_ICON_SIZE;

    if ( w > maximumWidth() ) {
        setMaximumWidth(w);
    }
}
Exemple #8
0
void TDockWidget::setDockedAppearance() {
  // No layout margin is visible when docked
  layout()->setMargin(0);

  if (m_floating)  // was floating
  {
    // Removing margin from extremal sizes
    int addition = 2 * m_margin;
    setMinimumSize(
        QSize(minimumWidth() - addition, minimumHeight() - addition));
    setMaximumSize(
        QSize(maximumWidth() - addition, maximumHeight() - addition));
  }
}
void CoverArtLabel::showArtUpdate( const QString& url )
{
    QPixmap pix;
    if( !url.isEmpty()  && pix.load( url ) )
    {
        pix = pix.scaled( maximumWidth(), maximumHeight(),
                          Qt::KeepAspectRatioByExpanding );
    }
    else
    {
        pix = QPixmap( ":/noart.png" );
    }
    setPixmap( pix );
}
Exemple #10
0
/**
 * \brief Set the current orientation
 * @param orientation as the given orientation
 */
void UBDockPalette::setOrientation(eUBDockOrientation orientation)
{
	// Set the size
	mOrientation = orientation;

	if(orientation == eUBDockOrientation_Left || orientation == eUBDockOrientation_Right)
	{
		setMaximumHeight(parentWidget()->height());
		setMinimumHeight(maximumHeight());
	}
	else if(orientation == eUBDockOrientation_Top || orientation == eUBDockOrientation_Bottom)
	{
		setMaximumWidth(parentWidget()->width());
		setMinimumWidth(maximumWidth());
	}
}
Exemple #11
0
	void SBWidget::AddTrayAction (QAction *act)
	{
		connect (act,
				SIGNAL (destroyed (QObject*)),
				this,
				SLOT (handleTrayActDestroyed ()));

		auto tb = new QToolButton;
		const int w = maximumWidth () - TrayLay_->margin () * 4;
		tb->setMaximumSize (w, w);
		tb->setIconSize (IconSize_);
		tb->setAutoRaise (true);
		tb->setDefaultAction (act);
		tb->setPopupMode (QToolButton::DelayedPopup);
		TrayAct2Button_ [act] = tb;

		TrayLay_->addWidget (tb);
	}
Exemple #12
0
void TDockWidget::setFloatingAppearance() {
  if (m_titlebar) {
    // If has a custom title bar, impose a margin to the layout
    // to provide a frame.
    layout()->setMargin(m_margin);

    if (!m_floating)  // was docked
    {
      // Adding margin to extremal sizes
      int addition = 2 * m_margin;
      setMinimumSize(
          QSize(minimumWidth() + addition, minimumHeight() + addition));
      setMaximumSize(
          QSize(maximumWidth() + addition, maximumHeight() + addition));
    }
  }
  // else
  //  setWindowFlags(Qt::Tool);
}
void PandemicWindow::mouseMoveEvent(QMouseEvent *event)
{

    if(_resizing == true)
    {
        if(_resizePoint & RightEdge)
        {
            resize(event->pos().x() + _resizePos.x(), height());
        }
        if(_resizePoint & BottomEdge)
        {
            resize(width(), event->pos().y() + _resizePos.y());
        }
        if(_resizePoint & LeftEdge)
        {
            QPoint offset = QPoint(event->pos().x() - _resizePos.x(), 0);\
            if(geometry().right() - (pos().x() + offset.x()) > minimumWidth() &&
               geometry().right() - (pos().x() + offset.x()) < maximumWidth()) move(pos() + offset);
            else if(geometry().right() - (pos().x() + offset.x()) > minimumWidth()) move(geometry().right() - (maximumWidth() - 1), pos().y());
            else move(geometry().right() - (minimumWidth() - 1), pos().y());
            resize(width() - offset.x(), height() - offset.y());
        }
        if(_resizePoint & TopEdge)
        {
            QPoint offset = QPoint(0, event->pos().y() - _resizePos.y());
            if(geometry().bottom() - (pos().y() + offset.y()) > minimumHeight() &&
               geometry().bottom() - (pos().y() + offset.y()) < maximumHeight()) move(pos() + offset);
            else if(geometry().bottom() - (pos().y() + offset.y()) > minimumHeight()) move(pos().x(), geometry().bottom() - (maximumHeight() - 1));
            else move(pos().x(), geometry().bottom() - (minimumHeight() - 1));
            resize(width() - offset.x(), height() - offset.y());
        }
    }

    int edges = hoveredEdges(event);
    if(edges == LeftEdge || edges == RightEdge) _cursor.setShape(Qt::SizeHorCursor);
    else if(edges == TopEdge || edges == BottomEdge) _cursor.setShape(Qt::SizeVerCursor);
    else if(edges == (TopEdge | LeftEdge) || edges == (BottomEdge | RightEdge)) _cursor.setShape(Qt::SizeFDiagCursor);
    else if(edges == (BottomEdge | LeftEdge) || edges == (TopEdge | RightEdge)) _cursor.setShape(Qt::SizeBDiagCursor);
    else _cursor.setShape(Qt::ArrowCursor);

    setCursor(_cursor);
}
Exemple #14
0
void mapWidget::emitMoveActionEnabled()
{
	int w, h;
	
	w = p_zoomW;
	h = p_zoomH;
	if (p_scrollBarsVisible)
	{
		w += p_scrollBarWidth;
		h += p_scrollBarHeight;
	}
	
	if (w < maximumWidth() * p_lastFactorX || h < maximumHeight() * p_lastFactorY)
	{
		p_scrollBarsVisible = true;
		emit setMoveActionEnabled(true);
	}
	else
	{
		p_scrollBarsVisible = false;
		emit setMoveActionChecked(false);
		emit setMoveActionEnabled(false);
	}
}
Exemple #15
0
void EWATextLabel::setText( const QString& text )
{
    QLabel::setText( fontMetrics().elidedText( text, Qt::ElideMiddle, maximumWidth() ).prepend( " " ) ); //-- hehe =)
    resize( getRectWithText().size() );
    updateBackgroundGradient();
}
Exemple #16
0
RepairerDialog::RepairerDialog(qReal::Repairer *repairer, QString const savePath)
{
	mRepairer = repairer;
	mSavePath = savePath;

	layout = new QGridLayout();

	mPatchSaveDialog = new PatchSaveDialog(savePath, "", mRepairer);
	mPatchSaveDialog->setMaximumSize(0,0);
	mPatchSaveDialog->setMaximumSize(maximumWidth(),maximumHeight());

	mAutorepairDialog = new QWidget();
	mAutorepairLayout = new QGridLayout();
	mAutorepairText = new QLabel(tr("QReal will use logs maded during working with editor."));	//todo: autodetect
	mAutorepairLayout->addWidget(mAutorepairText,0,0,1,-1,Qt::AlignCenter);
	mAutorepairDialog->setLayout(mAutorepairLayout);

	mGenerateEditorDialog = new QWidget();
	mGenerateEditorLayout = new QGridLayout();
	mGenerateEditorText = new QLabel(tr("Choose path to editor XML"));
	mGenerateEditorPath = new QLineEdit();
	mGenerateEditorPathError = new QLabel(tr("Path is incorrect"));
	mGenerateEditorPathCaption = new QLabel(tr("Path to XML:    "));
	mGenerateEditorPathBrowse = new QPushButton(tr("Browse"));
	mGenerateEditorLayout->addWidget(mGenerateEditorText,0,0,1,-1,Qt::AlignLeft);
	mGenerateEditorLayout->addWidget(mGenerateEditorPathCaption,1,0);
	mGenerateEditorLayout->addWidget(mGenerateEditorPath,1,1);
	mGenerateEditorLayout->addWidget(mGenerateEditorPathBrowse,1,2);
	mGenerateEditorLayout->addWidget(mGenerateEditorPathError,2,1,1,-1,Qt::AlignLeft);
	mGenerateEditorPathError->setStyleSheet("QLabel {color : red; }");
	mGenerateEditorPathError->hide();
	mGenerateEditorDialog->setLayout(mGenerateEditorLayout);

	mPatchSaveSwitcher = new QCheckBox(tr("Patch save"));
	mAutorepairSwitcher = new QCheckBox(tr("Try to repair save automatically"));
	mGenerateEditorSwitcher = new QCheckBox(tr("Generate new editor from file"));

	mCommonText = new QLabel(tr("Current save cannot be loaded.\nChoose ways to fix it:"));
	mRunButton = new QPushButton(tr("Run"));

	layout->addWidget(mCommonText,0,0,1,-1,Qt::AlignLeft);
	layout->addWidget(mPatchSaveSwitcher,1,0,1,-1,Qt::AlignLeft);
	layout->addWidget(mPatchSaveDialog,2,0);
	layout->addWidget(mAutorepairSwitcher,3,0,1,-1,Qt::AlignLeft);
	layout->addWidget(mAutorepairDialog,4,0);
	layout->addWidget(mGenerateEditorSwitcher,5,0,1,-1,Qt::AlignLeft);
	layout->addWidget(mGenerateEditorDialog,6,0);
	layout->addWidget(mRunButton,7,0,1,-1,Qt::AlignCenter);

	setLayout(layout);

	mPatchSaveDialog->hide();
	mAutorepairDialog->hide();
	mGenerateEditorDialog->hide();

	QPushButton* patchSaveRunButton = mPatchSaveDialog->getRunButton();
	patchSaveRunButton->hide();

	connect(mRunButton, SIGNAL(clicked()),this,SLOT(run()));
	connect(mGenerateEditorPathBrowse, SIGNAL(clicked()),this,SLOT(openEditorXML()));
	connect(mGenerateEditorPath, SIGNAL(editingFinished()), this, SLOT(checkEditorPath()));

	connectSwitchers();

	int width = this->width() + 20;
	setFixedSize(width,heightForWidth(width));

	mAutorepairSwitcher->toggle();
}
bool CFramelessWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    MSG* msg = (MSG *)message;
    switch (msg->message)
    {
    case WM_NCCALCSIZE:
    {
        //this kills the window frame and title bar we added with WS_THICKFRAME and WS_CAPTION
        *result = 0;
        return true;
    }
    case WM_NCHITTEST:
    {
        *result = 0;

        const LONG border_width = m_borderWidth;
        RECT winrect;
        GetWindowRect(HWND(winId()), &winrect);

        long x = GET_X_LPARAM(msg->lParam);
        long y = GET_Y_LPARAM(msg->lParam);

        if(m_bResizeable)
        {

            bool resizeWidth = minimumWidth() != maximumWidth();
            bool resizeHeight = minimumHeight() != maximumHeight();

            if(resizeWidth)
            {
                //left border
                if (x >= winrect.left && x < winrect.left + border_width)
                {
                    *result = HTLEFT;
                }
                //right border
                if (x < winrect.right && x >= winrect.right - border_width)
                {
                    *result = HTRIGHT;
                }
            }
            if(resizeHeight)
            {
                //bottom border
                if (y < winrect.bottom && y >= winrect.bottom - border_width)
                {
                    *result = HTBOTTOM;
                }
                //top border
                if (y >= winrect.top && y < winrect.top + border_width)
                {
                    *result = HTTOP;
                }
            }
            if(resizeWidth && resizeHeight)
            {
                //bottom left corner
                if (x >= winrect.left && x < winrect.left + border_width &&
                        y < winrect.bottom && y >= winrect.bottom - border_width)
                {
                    *result = HTBOTTOMLEFT;
                }
                //bottom right corner
                if (x < winrect.right && x >= winrect.right - border_width &&
                        y < winrect.bottom && y >= winrect.bottom - border_width)
                {
                    *result = HTBOTTOMRIGHT;
                }
                //top left corner
                if (x >= winrect.left && x < winrect.left + border_width &&
                        y >= winrect.top && y < winrect.top + border_width)
                {
                    *result = HTTOPLEFT;
                }
                //top right corner
                if (x < winrect.right && x >= winrect.right - border_width &&
                        y >= winrect.top && y < winrect.top + border_width)
                {
                    *result = HTTOPRIGHT;
                }
            }
        }
        if (0!=*result) return true;

        //*result still equals 0, that means the cursor locate OUTSIDE the frame area
        //but it may locate in titlebar area
        if (!m_titlebar) return false;

        //support highdpi
        double dpr = this->devicePixelRatioF();
        QPoint pos = m_titlebar->mapFromGlobal(QPoint(x/dpr,y/dpr));

        if (!m_titlebar->rect().contains(pos)) return false;
        QWidget* child = m_titlebar->childAt(pos);
        if (!child)
        {
            *result = HTCAPTION;
            return true;
        }else{
            if (m_whiteList.contains(child))
            {
                *result = HTCAPTION;
                return true;
            }
        }
        return false;
    } //end case WM_NCHITTEST
    case WM_GETMINMAXINFO:
    {
        if (::IsZoomed(msg->hwnd)) {
            RECT frame = { 0, 0, 0, 0 };
            AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0);

            //record frame area data
            double dpr = this->devicePixelRatioF();

            m_frames.setLeft(abs(frame.left)/dpr+0.5);
            m_frames.setTop(abs(frame.bottom)/dpr+0.5);
            m_frames.setRight(abs(frame.right)/dpr+0.5);
            m_frames.setBottom(abs(frame.bottom)/dpr+0.5);

            QMainWindow::setContentsMargins(m_frames.left()+m_margins.left(), \
                                            m_frames.top()+m_margins.top(), \
                                            m_frames.right()+m_margins.right(), \
                                            m_frames.bottom()+m_margins.bottom());
            m_bJustMaximized = true;
        }else {
            if (m_bJustMaximized)
            {
                QMainWindow::setContentsMargins(m_margins);
                //after window back to normal size from maximized state
                //a twinkle will happen, to avoid this twinkle
                //repaint() is important used just before the window back to normal
                repaint();
                m_frames = QMargins();
                m_bJustMaximized = false;
            }
        }
        return false;
    }
    default:
        return QMainWindow::nativeEvent(eventType, message, result);
    }
}
int QWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 23)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 23;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< bool*>(_v) = isModal(); break;
        case 1: *reinterpret_cast< Qt::WindowModality*>(_v) = windowModality(); break;
        case 2: *reinterpret_cast< bool*>(_v) = isEnabled(); break;
        case 3: *reinterpret_cast< QRect*>(_v) = geometry(); break;
        case 4: *reinterpret_cast< QRect*>(_v) = frameGeometry(); break;
        case 5: *reinterpret_cast< QRect*>(_v) = normalGeometry(); break;
        case 6: *reinterpret_cast< int*>(_v) = x(); break;
        case 7: *reinterpret_cast< int*>(_v) = y(); break;
        case 8: *reinterpret_cast< QPoint*>(_v) = pos(); break;
        case 9: *reinterpret_cast< QSize*>(_v) = frameSize(); break;
        case 10: *reinterpret_cast< QSize*>(_v) = size(); break;
        case 11: *reinterpret_cast< int*>(_v) = width(); break;
        case 12: *reinterpret_cast< int*>(_v) = height(); break;
        case 13: *reinterpret_cast< QRect*>(_v) = rect(); break;
        case 14: *reinterpret_cast< QRect*>(_v) = childrenRect(); break;
        case 15: *reinterpret_cast< QRegion*>(_v) = childrenRegion(); break;
        case 16: *reinterpret_cast< QSizePolicy*>(_v) = sizePolicy(); break;
        case 17: *reinterpret_cast< QSize*>(_v) = minimumSize(); break;
        case 18: *reinterpret_cast< QSize*>(_v) = maximumSize(); break;
        case 19: *reinterpret_cast< int*>(_v) = minimumWidth(); break;
        case 20: *reinterpret_cast< int*>(_v) = minimumHeight(); break;
        case 21: *reinterpret_cast< int*>(_v) = maximumWidth(); break;
        case 22: *reinterpret_cast< int*>(_v) = maximumHeight(); break;
        case 23: *reinterpret_cast< QSize*>(_v) = sizeIncrement(); break;
        case 24: *reinterpret_cast< QSize*>(_v) = baseSize(); break;
        case 25: *reinterpret_cast< QPalette*>(_v) = palette(); break;
        case 26: *reinterpret_cast< QFont*>(_v) = font(); break;
        case 27: *reinterpret_cast< QCursor*>(_v) = cursor(); break;
        case 28: *reinterpret_cast< bool*>(_v) = hasMouseTracking(); break;
        case 29: *reinterpret_cast< bool*>(_v) = isActiveWindow(); break;
        case 30: *reinterpret_cast< Qt::FocusPolicy*>(_v) = focusPolicy(); break;
        case 31: *reinterpret_cast< bool*>(_v) = hasFocus(); break;
        case 32: *reinterpret_cast< Qt::ContextMenuPolicy*>(_v) = contextMenuPolicy(); break;
        case 33: *reinterpret_cast< bool*>(_v) = updatesEnabled(); break;
        case 34: *reinterpret_cast< bool*>(_v) = isVisible(); break;
        case 35: *reinterpret_cast< bool*>(_v) = isMinimized(); break;
        case 36: *reinterpret_cast< bool*>(_v) = isMaximized(); break;
        case 37: *reinterpret_cast< bool*>(_v) = isFullScreen(); break;
        case 38: *reinterpret_cast< QSize*>(_v) = sizeHint(); break;
        case 39: *reinterpret_cast< QSize*>(_v) = minimumSizeHint(); break;
        case 40: *reinterpret_cast< bool*>(_v) = acceptDrops(); break;
        case 41: *reinterpret_cast< QString*>(_v) = windowTitle(); break;
        case 42: *reinterpret_cast< QIcon*>(_v) = windowIcon(); break;
        case 43: *reinterpret_cast< QString*>(_v) = windowIconText(); break;
        case 44: *reinterpret_cast< double*>(_v) = windowOpacity(); break;
        case 45: *reinterpret_cast< bool*>(_v) = isWindowModified(); break;
        case 46: *reinterpret_cast< QString*>(_v) = toolTip(); break;
        case 47: *reinterpret_cast< QString*>(_v) = statusTip(); break;
        case 48: *reinterpret_cast< QString*>(_v) = whatsThis(); break;
        case 49: *reinterpret_cast< QString*>(_v) = accessibleName(); break;
        case 50: *reinterpret_cast< QString*>(_v) = accessibleDescription(); break;
        case 51: *reinterpret_cast< Qt::LayoutDirection*>(_v) = layoutDirection(); break;
        case 52: *reinterpret_cast< bool*>(_v) = autoFillBackground(); break;
        case 53: *reinterpret_cast< QString*>(_v) = styleSheet(); break;
        case 54: *reinterpret_cast< QLocale*>(_v) = locale(); break;
        case 55: *reinterpret_cast< QString*>(_v) = windowFilePath(); break;
        case 56: *reinterpret_cast< Qt::InputMethodHints*>(_v) = inputMethodHints(); break;
        }
        _id -= 57;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 1: setWindowModality(*reinterpret_cast< Qt::WindowModality*>(_v)); break;
        case 2: setEnabled(*reinterpret_cast< bool*>(_v)); break;
        case 3: setGeometry(*reinterpret_cast< QRect*>(_v)); break;
        case 8: move(*reinterpret_cast< QPoint*>(_v)); break;
        case 10: resize(*reinterpret_cast< QSize*>(_v)); break;
        case 16: setSizePolicy(*reinterpret_cast< QSizePolicy*>(_v)); break;
        case 17: setMinimumSize(*reinterpret_cast< QSize*>(_v)); break;
        case 18: setMaximumSize(*reinterpret_cast< QSize*>(_v)); break;
        case 19: setMinimumWidth(*reinterpret_cast< int*>(_v)); break;
        case 20: setMinimumHeight(*reinterpret_cast< int*>(_v)); break;
        case 21: setMaximumWidth(*reinterpret_cast< int*>(_v)); break;
        case 22: setMaximumHeight(*reinterpret_cast< int*>(_v)); break;
        case 23: setSizeIncrement(*reinterpret_cast< QSize*>(_v)); break;
        case 24: setBaseSize(*reinterpret_cast< QSize*>(_v)); break;
        case 25: setPalette(*reinterpret_cast< QPalette*>(_v)); break;
        case 26: setFont(*reinterpret_cast< QFont*>(_v)); break;
        case 27: setCursor(*reinterpret_cast< QCursor*>(_v)); break;
        case 28: setMouseTracking(*reinterpret_cast< bool*>(_v)); break;
        case 30: setFocusPolicy(*reinterpret_cast< Qt::FocusPolicy*>(_v)); break;
        case 32: setContextMenuPolicy(*reinterpret_cast< Qt::ContextMenuPolicy*>(_v)); break;
        case 33: setUpdatesEnabled(*reinterpret_cast< bool*>(_v)); break;
        case 34: setVisible(*reinterpret_cast< bool*>(_v)); break;
        case 40: setAcceptDrops(*reinterpret_cast< bool*>(_v)); break;
        case 41: setWindowTitle(*reinterpret_cast< QString*>(_v)); break;
        case 42: setWindowIcon(*reinterpret_cast< QIcon*>(_v)); break;
        case 43: setWindowIconText(*reinterpret_cast< QString*>(_v)); break;
        case 44: setWindowOpacity(*reinterpret_cast< double*>(_v)); break;
        case 45: setWindowModified(*reinterpret_cast< bool*>(_v)); break;
        case 46: setToolTip(*reinterpret_cast< QString*>(_v)); break;
        case 47: setStatusTip(*reinterpret_cast< QString*>(_v)); break;
        case 48: setWhatsThis(*reinterpret_cast< QString*>(_v)); break;
        case 49: setAccessibleName(*reinterpret_cast< QString*>(_v)); break;
        case 50: setAccessibleDescription(*reinterpret_cast< QString*>(_v)); break;
        case 51: setLayoutDirection(*reinterpret_cast< Qt::LayoutDirection*>(_v)); break;
        case 52: setAutoFillBackground(*reinterpret_cast< bool*>(_v)); break;
        case 53: setStyleSheet(*reinterpret_cast< QString*>(_v)); break;
        case 54: setLocale(*reinterpret_cast< QLocale*>(_v)); break;
        case 55: setWindowFilePath(*reinterpret_cast< QString*>(_v)); break;
        case 56: setInputMethodHints(*reinterpret_cast< Qt::InputMethodHints*>(_v)); break;
        }
        _id -= 57;
    } else if (_c == QMetaObject::ResetProperty) {
        switch (_id) {
        case 27: unsetCursor(); break;
        case 51: unsetLayoutDirection(); break;
        case 54: unsetLocale(); break;
        }
        _id -= 57;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        bool *_b = reinterpret_cast<bool*>(_a[0]);
        switch (_id) {
        case 41: *_b = isWindow(); break;
        case 42: *_b = isWindow(); break;
        case 43: *_b = isWindow(); break;
        case 44: *_b = isWindow(); break;
        case 45: *_b = isWindow(); break;
        case 55: *_b = isWindow(); break;
        }
        _id -= 57;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 57;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 57;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 57;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 57;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemple #19
0
void Widget::onClipboardUpdated()
{
    QClipboard *clip = qApp->clipboard();

    if (clip->mimeData()->hasImage()) {
        QImage image = clip->image();
        QSize origSize = image.size();
        const int minWidth = minimumWidth() - 20;
        const int minHeight = minimumHeight() - 20;
        if (image.width() <= image.height() && image.height() < minimumHeight() - 20) {
            image = image.scaledToHeight(minHeight);
        } else if (image.width() < minWidth) {
            image = image.scaledToWidth(minWidth);
        }
        if (image.width() > maximumWidth() - 10) {
            image = image.scaledToWidth(maximumWidth() - 10);
        }
        if (image.height() > maximumHeight() - 10) {
            image = image.scaledToHeight(maximumHeight() - 10);
        }

        {
            QPainter p(&image);
            QFont font;
            font.setPixelSize(15);
            p.setFont(font);
            QFontMetrics metrics(font);
            QString text = QString::number(origSize.width()) + "x" + QString::number(origSize.height());
            QRect rect = metrics.boundingRect(text).marginsAdded(QMargins(5, 5, 5, 5));
            rect.moveTopLeft(QPoint(0, 0));
            p.fillRect(rect, QColor(0, 0, 0, 128));
            p.setPen(Qt::white);
            p.drawText(rect, Qt::AlignCenter, text);
        }

        m_label->setPixmap(QPixmap::fromImage(image));
        resize(image.size());
        updateGeometry();
        m_hasTrimmed = false;
        return;
    }

    QString text = clip->text();

    const QStringList formats = clip->mimeData()->formats();
    bool onlyTextPlain = formats.contains("text/plain");
    if (onlyTextPlain) {
        for (const QString &format : formats) {
            // "Special" fake mimetypes to indicate multiselections etc.
            if (!format.contains('/') || format.toUpper() == format) {
                continue;
            }
            if (format == "text/plain" || format == "text/html") {
                continue;
            }
            onlyTextPlain = false;
            break;
        }

        QString trimmed = text.trimmed();

        if (onlyTextPlain && trimmed != text && !m_hasTrimmed) {
            clip->setText(trimmed);
            m_hasTrimmed = true;
            return;
        }
    }

    m_hasTrimmed = false;

    QFontMetrics metrics(font());

    QString filteredText;
    for (const QChar &c : text) {
        if ((c.isPrint() || c == '\n' || c == '\t') && (c.script() == QChar::Script_Latin || c.script() == QChar::Script_Common)) {
            filteredText += c;
            continue;
        }

        qDebug() << c << c.script() << c.category();

        filteredText += "0x" + QString::number(c.unicode(), 16);
    }
    text = filteredText;

    QRect boundingRect = QRect(0, 0, maximumWidth(), maximumHeight());
    boundingRect = metrics.boundingRect(boundingRect, Qt::TextWordWrap, text);
    boundingRect = boundingRect.marginsAdded(QMargins(20, 20, 20, 20));

    if (boundingRect.height() > maximumHeight()) {
        m_label->setWordWrap(false);

        QString newText;
        int h = metrics.height() * 2;
        for (const QString &line : text.split('\n')) {
            newText.append(metrics.elidedText(line, Qt::ElideRight, m_label->width() - 20) + '\n');
            h += metrics.height();
        }
        text = newText;
        boundingRect.setHeight(h);
    } else {
        m_label->setWordWrap(true);
    }
    resize(boundingRect.size());

    m_label->setText(text);
    m_label->setSelection(0, text.length());
    updateGeometry();
}
void YaTabBarBase::drawTab(QPainter* painter, int index, const QRect& tabRect)
{
	QStyleOptionTabV2 tab = getStyleOption(index);
	if (!(tab.state & QStyle::State_Enabled)) {
		tab.palette.setCurrentColorGroup(QPalette::Disabled);
	}

	// Don't bother drawing a tab if the entire tab is outside of the visible tab bar.
	if (tabRect.right() < 0 ||
	    tabRect.left() > width() ||
	    tabRect.bottom() < 0 ||
	    tabRect.top() > height() ||
	    tabRect.width() < 3)
	{
		return;
	}

	bool isCurrent = index == currentIndex();
	bool isHovered = tabHovered(index);
	bool isHighlighted = tabData(index).toBool();

	QColor backgroundColor = this->tabBackgroundColor();
	if (isCurrent) {
#ifndef WIDGET_PLUGIN
		backgroundColor = Ya::VisualUtil::editAreaColor();
#else
		backgroundColor = Qt::white;
#endif
	}
	else if (isHovered) {
#ifndef WIDGET_PLUGIN
		backgroundColor = Ya::VisualUtil::tabHighlightColor();
#else
		backgroundColor = Qt::gray;
#endif
	}
	else if (isHighlighted) {
		backgroundColor = highlightColor();
	}

	if (backgroundColor.isValid()) {
		painter->fillRect(tabRect, backgroundColor);
	}

	painter->save();
#ifndef WIDGET_PLUGIN
	painter->setPen(Ya::VisualUtil::rosterTabBorderColor());
#endif

	bool drawLeftLine  = tabRect.left() != rect().left();
	bool drawRightLine = true; // tabRect.right() != rect().right() || rect().width() < maximumWidth();

	switch (shape()) {
	case YaTabBarBase::RoundedSouth:
	case YaTabBarBase::TriangularSouth:
		if (isMultiLine())
			drawRightLine = tabRect.right() + 1 < maximumWidth();

		if (!isCurrent || isMultiLine())
			painter->drawLine(tabRect.topLeft(), tabRect.topRight());

		if (isCurrent) {
			if (drawLeftLine && !isMultiLine())
				painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft());
			if (drawRightLine)
				painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
		}
		else {
			if (isHovered || isMultiLine()) {
				if (currentIndex() != (index - 1) && !isMultiLine())
					if (drawLeftLine)
						painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft());
				if (currentIndex() != (index + 1) || isMultiLine())
					if (drawRightLine)
						painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
			}
		}
		break;
	default:
		Q_ASSERT(false);
		break;
	}

	painter->restore();

	tabIcon(index).paint(painter, tabIconRect(index));

	QRect textRect = tabTextRect(index);
	QString text = tabText(index);

	if (drawTabNumbers_ && index < 10) {
		int numberToDraw = index + 1;
		if (numberToDraw > 9) {
			numberToDraw = 0;
		}

		painter->save();
		painter->setPen(Qt::gray);
		QString numberToDrawText = QString::number(numberToDraw) + " ";
		painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, numberToDrawText);
		textRect.adjust(fontMetrics().width(numberToDrawText), 0, 0, 0);
		painter->restore();
	}

	painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, text);
#ifndef WIDGET_PLUGIN
	if (textWidth(text) > textRect.width() && backgroundColor.isValid()) {
		Ya::VisualUtil::drawTextFadeOut(painter, textRect.adjusted(1, 0, 1, 0), backgroundColor, 15);
	}
#endif

	if (isMultiLine()) {
		QPixmap shadow(tabShadow(isCurrent));
		QRect r(tabRect);
		r.setHeight(shadow.height());
		painter->drawTiledPixmap(r, shadow);
	}
}