Ejemplo n.º 1
0
void KisColorPatches::resizeEvent(QResizeEvent* event)
{
    if(size()==QSize(1, 1))
        return;

    QWheelEvent dummyWheelEvent(QPoint(), 0, Qt::NoButton, Qt::NoModifier);
    wheelEvent(&dummyWheelEvent);

    if(parentWidget()==0) {
        // this instance is a popup
        setMinimumWidth(m_patchWidth*(m_patchCount/4));
        setMaximumWidth(minimumWidth());
    }

    if(m_allowScrolling == false && event->oldSize() != event->size()) {
        if(m_direction == Horizontal) {
            setMaximumHeight(heightForWidth(width()));
            setMinimumHeight(heightForWidth(width()));
        }
        else {
            setMaximumWidth(widthForHeight(height()));
            setMinimumWidth(widthForHeight(height()));
        }
    }
}
Ejemplo n.º 2
0
void SavegameDialog::refreshWindowSize()
{
    // DPI calculation
    qreal screenRatio = AppEnv::screenRatio();
    int dpiWindowWidth = 400 * screenRatio;
    int dpiWindowHeight = 105 * screenRatio;
    if (dpiWindowHeight < heightForWidth(dpiWindowWidth))
    {
        dpiWindowHeight = heightForWidth(dpiWindowWidth);
    }
    resize(dpiWindowWidth, dpiWindowHeight);
}
Ejemplo n.º 3
0
void TipLabel::show(const QRect &tipRect, bool bState)
{
    setAlignment( WordBreak | AlignCenter );
    QRect rc = screenGeometry();
    QSize s = sizeHint();
    int h = heightForWidth(s.width());
    resize(s.width(), h );
    int x = tipRect.left() + tipRect.width() / 2 - width();
    if (x < 0)
        x = tipRect.left() + tipRect.width() / 2;
    if (x + width() > rc.width() - 2)
        x = rc.width() - 2 - width();
    int y;
    if (bState){
        y = tipRect.top() - 4 - height();
        if (y < 0)
            bState = false;
    }
    if (!bState)
        y = tipRect.top() + tipRect.height() + 4;
    if (y + height() > rc.height())
        y = tipRect.top() - 4 - height();
    if (y < 0)
        y = tipRect.top() + tipRect.height() + 4;
    move(x, y);
    QLabel::show();
}
Ejemplo n.º 4
0
void TextTip::configure(const QPoint &pos, QWidget *w)
{
    const QString &text = static_cast<const TextContent &>(content()).text();
    setText(text);

    // Make it look good with the default ToolTip font on Mac, which has a small descent.
    QFontMetrics fm(font());
    int extraHeight = 0;
    if (fm.descent() == 2 && fm.ascent() >= 11)
        ++extraHeight;

    // Try to find a nice width without unnecessary wrapping.
    setWordWrap(false);
    int tipWidth = sizeHint().width();
    const int screenWidth = screenGeometry(pos, w).width();
    const int maxDesiredWidth = int(screenWidth * .5);
    if (tipWidth > maxDesiredWidth) {
        setWordWrap(true);
        tipWidth = sizeHint().width();
        // If the width is still too large (maybe due to some extremely long word which prevents
        // wrapping), the tip is truncated according to the screen.
        if (tipWidth > screenWidth)
            tipWidth = screenWidth - 10;
    }

    resize(tipWidth, heightForWidth(tipWidth) + extraHeight);
}
Ejemplo n.º 5
0
void c_image_Widget::resizeEvent(QResizeEvent *e)
{
    int w = e->size().width();
    int h = heightForWidth(w);
    m_current_Size = QSize(w, h);
    updateGeometry();
}
Ejemplo n.º 6
0
/*!
  Sets the geometry of this item's widget to be contained within \a r,
  taking alignment and maximum size into account.
*/
void QWidgetItem::setGeometry( const QRect &r )
{
    QSize s = r.size().boundedTo( smartMaxSize( wid ) );
    int x = r.x();
    int y = r.y();
    if ( align & (HorAlign|VerAlign) ) {
	QSize pref = wid->sizeHint().expandedTo( wid->minimumSize() ); //###
	if ( align & HorAlign )
	    s.setWidth( QMIN( s.width(), pref.width() ) );
	if ( align & VerAlign ) {
	    if ( hasHeightForWidth() )
		s.setHeight( QMIN( s.height(), heightForWidth(s.width()) ) );
	    else
		s.setHeight( QMIN( s.height(), pref.height() ) );
	}
    }
    if ( align & Qt::AlignRight )
	x = x + ( r.width() - s.width() );
    else if ( !(align & Qt::AlignLeft) )
	x = x + ( r.width() - s.width() ) / 2;

    if ( align & Qt::AlignBottom )
	y = y + ( r.height() - s.height() );
    else if ( !(align & Qt::AlignTop) )
	y = y + ( r.height() - s.height() ) / 2;

    if ( !wid->isHidden() && !wid->isTopLevel() )
	wid->setGeometry( x, y, s.width(), s.height() );
}
Ejemplo n.º 7
0
AppletHandle::AppletHandle(AppletContainer* parent)
    : QWidget(parent),
      m_applet(parent),
      m_menuButton(0),
      m_drawHandle(false),
      m_popupDirection(KPanelApplet::Up),
      m_handleHoverTimer(0)
{
    setBackgroundOrigin(AncestorOrigin);
    setMinimumSize(widthForHeight(0), heightForWidth(0));
    m_layout = new QBoxLayout(this, QBoxLayout::BottomToTop, 0, 0);

    m_dragBar = new AppletHandleDrag(this);
    m_dragBar->installEventFilter(this);
    m_layout->addWidget(m_dragBar);

    if (kapp->authorizeKAction("kicker_rmb"))
    {
        m_menuButton = new AppletHandleButton( this );
        m_menuButton->setPixmap(xpmPixmap(up_xpm, "up"));
        m_menuButton->installEventFilter(this);
        m_layout->addWidget(m_menuButton);

        connect(m_menuButton, SIGNAL(pressed()),
                this, SLOT(menuButtonPressed()));
        QToolTip::add(m_menuButton, i18n("%1 menu").arg(parent->info().name()));
    }

    QToolTip::add(this, i18n("%1 applet handle").arg(parent->info().name()));
    resetLayout();
}
Ejemplo n.º 8
0
void TextTip::configure(const QPoint &pos, QWidget *w)
{
    if (helpId().isEmpty())
        setText(m_text);
    else
        setText(QString::fromLatin1("<table><tr><td valign=middle>%1</td><td>&nbsp;&nbsp;"
                                    "<img src=\":/utils/tooltip/images/f1.png\"></td>"
                                    "</tr></table>").arg(m_text));

    // Make it look good with the default ToolTip font on Mac, which has a small descent.
    QFontMetrics fm(font());
    int extraHeight = 0;
    if (fm.descent() == 2 && fm.ascent() >= 11)
        ++extraHeight;

    // Try to find a nice width without unnecessary wrapping.
    setWordWrap(false);
    int tipWidth = sizeHint().width();
    const int screenWidth = screenGeometry(pos, w).width();
    const int maxDesiredWidth = int(screenWidth * .5);
    if (tipWidth > maxDesiredWidth) {
        setWordWrap(true);
        tipWidth = sizeHint().width();
        // If the width is still too large (maybe due to some extremely long word which prevents
        // wrapping), the tip is truncated according to the screen.
        if (tipWidth > screenWidth)
            tipWidth = screenWidth - 10;
    }

    resize(tipWidth, heightForWidth(tipWidth) + extraHeight);
}
Ejemplo n.º 9
0
QRect QLayout::alignmentRect( const QRect &r ) const
{
    QSize s = sizeHint();
    int a = alignment();
    if ( expanding() & QSizePolicy::Horizontal || !(a & HorAlign ) ) {
	s.setWidth( r.width() );
    }
    if ( expanding() & QSizePolicy::Vertical || !(a & VerAlign )) {
	s.setHeight( r.height() );
    } else if ( hasHeightForWidth() ) {
	s.setHeight( QMIN( s.height(), heightForWidth(s.width()) ) );
    }

    int x = r.x();
    int y = r.y();

    if ( a & Qt::AlignRight )
	x = x + ( r.width() - s.width() );
    else if ( !(a & Qt::AlignLeft) )
	x = x + ( r.width() - s.width() ) / 2;

    if ( a & Qt::AlignBottom )
	y = y + ( r.height() - s.height() );
    else if ( !(a & Qt::AlignTop) )
	y = y + ( r.height() - s.height() ) / 2;

    return QRect( x, y, s.width(), s.height() );

}
Ejemplo n.º 10
0
void LinkDisplay::setLink(const QString &title, const QString &icon, const QPixmap &preview, LinkLook *look, const QFont &font)
{
    m_title   = title;
    m_icon    = icon;
    m_preview = preview;
    m_look    = look;
    m_font    = font;

    // "Constants":
    int BUTTON_MARGIN = kapp->style()->pixelMetric(QStyle::PM_ButtonMargin);
    int LINK_MARGIN   = BUTTON_MARGIN + 2;

    // Recompute m_minWidth:
    QRect textRect = QFontMetrics(labelFont(font, false)).boundingRect(0, 0, /*width=*/1, 500000, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, m_title);
    int iconPreviewWidth = qMax(m_look->iconSize(), (m_look->previewEnabled() ? m_preview.width() : 0));
    m_minWidth = BUTTON_MARGIN - 1 + iconPreviewWidth + LINK_MARGIN + textRect.width();
    // Recompute m_maxWidth:
    textRect = QFontMetrics(labelFont(font, false)).boundingRect(0, 0, /*width=*/50000000, 500000, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, m_title);
    m_maxWidth = BUTTON_MARGIN - 1 + iconPreviewWidth + LINK_MARGIN + textRect.width();
    // Adjust m_width:
    if (m_width < m_minWidth)
        setWidth(m_minWidth);
    // Recompute m_height:
    m_height = heightForWidth(m_width);
}
Ejemplo n.º 11
0
void Palette::contextMenuEvent(QContextMenuEvent* event)
      {
      int i = idx(event->pos());
      if (i == -1) {
            // palette context menu
            QMenu menu;
            QAction* moreAction = menu.addAction(tr("Show More..."));
            moreAction->setEnabled(_moreElements);
            QAction* action = menu.exec(mapToGlobal(event->pos()));
            if (action == moreAction)
                  emit displayMore(_name);
            return;
            }

      QMenu menu;
      QAction* clearAction   = menu.addAction(tr("Clear"));
      QAction* contextAction = menu.addAction(tr("Properties..."));
      clearAction->setEnabled(!_readOnly);
      contextAction->setEnabled(!_readOnly);
      QAction* moreAction    = menu.addAction(tr("Show More..."));
      moreAction->setEnabled(_moreElements);

      if (cells[i] && cells[i]->readOnly)
            clearAction->setEnabled(false);

      QAction* action = menu.exec(mapToGlobal(event->pos()));

      if (action == clearAction) {
            PaletteCell* cell = cells[i];
            if (cell) {
                  delete cell->element;
                  delete cell;
                  }
            cells[i] = 0;
            emit changed();
            }
      else if (action == contextAction) {
            PaletteCell* c = cells[i];
            if (c == 0)
                  return;
            PaletteCellProperties props(c);
            if (props.exec()) {
                  emit changed();
                  }
            }
      else if (moreAction && (action == moreAction))
            emit displayMore(_name);

      bool sizeChanged = false;
      while (!cells.isEmpty() && cells.back() == 0) {
            cells.removeLast();
            sizeChanged = true;
            }
      if (sizeChanged) {
            setFixedHeight(heightForWidth(width()));
            updateGeometry();
            }
      update();
      }
int  QAbstractPageSetupDialog_QtDShell::__override_heightForWidth(int  arg__1, bool static_call) const
{
    if (static_call) {
        return QWidget::heightForWidth((int )arg__1);
    } else {
        return heightForWidth((int )arg__1);
    }
}
Ejemplo n.º 13
0
/*!
    \reimp
*/
int QBoxLayout::minimumHeightForWidth(int w) const
{
    Q_D(const QBoxLayout);
    (void) heightForWidth(w);
    int top, bottom;
    d->effectiveMargins(0, &top, 0, &bottom);
    return d->hasHfw ? (d->hfwMinHeight + top + bottom) : -1;
}
Ejemplo n.º 14
0
int  QWidgetItem_QtDShell::__override_heightForWidth(int  arg__1, bool static_call) const
{
    if (static_call) {
        return QWidgetItem::heightForWidth((int )arg__1);
    } else {
        return heightForWidth((int )arg__1);
    }
}
Ejemplo n.º 15
0
int  QBoxLayout_QtDShell::__override_heightForWidth(int  arg__1, bool static_call) const
{
    if (static_call) {
        return QBoxLayout::heightForWidth((int )arg__1);
    } else {
        return heightForWidth((int )arg__1);
    }
}
Ejemplo n.º 16
0
QSize QgsPixmapLabel::sizeHint() const
{
  if ( mPixmap.isNull() )
    return QSize( 0, 0 );

  int w = this->width();
  return QSize( w, heightForWidth( w ) );
}
Ejemplo n.º 17
0
/*!
    \reimp
*/
void QWidgetItem::setGeometry(const QRect &rect)
{
    if (isEmpty())
        return;

    QRect r = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
            ? fromLayoutItemRect(wid->d_func(), rect)
            : rect;
    const QSize widgetRectSurplus = r.size() - rect.size(); 

    /* 
       For historical reasons, this code is done using widget rect 
       coordinates, not layout item rect coordinates. However, 
       QWidgetItem's sizeHint(), maximumSize(), and heightForWidth() 
       all work in terms of layout item rect coordinates, so we have to 
       add or subtract widgetRectSurplus here and there. The code could 
       be much simpler if we did everything using layout item rect 
       coordinates and did the conversion right before the call to 
       QWidget::setGeometry(). 
     */ 

    QSize s = r.size().boundedTo(maximumSize() + widgetRectSurplus);  
    int x = r.x();
    int y = r.y();
    if (align & (Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask)) {
        QSize pref(sizeHint());
        QSizePolicy sp = wid->sizePolicy();
        if (sp.horizontalPolicy() == QSizePolicy::Ignored)
            pref.setWidth(wid->sizeHint().expandedTo(wid->minimumSize()).width());
        if (sp.verticalPolicy() == QSizePolicy::Ignored)
            pref.setHeight(wid->sizeHint().expandedTo(wid->minimumSize()).height());
        pref += widgetRectSurplus;
        if (align & Qt::AlignHorizontal_Mask)
            s.setWidth(qMin(s.width(), pref.width()));
        if (align & Qt::AlignVertical_Mask) {
            if (hasHeightForWidth())
                s.setHeight(qMin(s.height(), 
                                 heightForWidth(s.width() - widgetRectSurplus.width()) 
                                 + widgetRectSurplus.height()));
            else
                s.setHeight(qMin(s.height(), pref.height()));
        }
    }
    Qt::Alignment alignHoriz = QStyle::visualAlignment(wid->layoutDirection(), align);
    if (alignHoriz & Qt::AlignRight)
        x = x + (r.width() - s.width());
    else if (!(alignHoriz & Qt::AlignLeft))
        x = x + (r.width() - s.width()) / 2;

    if (align & Qt::AlignBottom)
        y = y + (r.height() - s.height());
    else if (!(align & Qt::AlignTop))
        y = y + (r.height() - s.height()) / 2;

    wid->setGeometry(x, y, s.width(), s.height());
}
Ejemplo n.º 18
0
void LinkDisplay::setWidth(qreal width)
{
    if (width < m_minWidth)
        width = m_minWidth;

    if (width != m_width) {
        m_width  = width;
        m_height = heightForWidth(m_width);
    }
}
Ejemplo n.º 19
0
// Description:  Returns the number of rows in the layout (may
//                be different than what the user set if autoGrow
//                is set to true).
//
int KxGridLayout::rowCount()
{
	if(fAutoGrow) {
		QRect rect = geometry();
		int height = heightForWidth(rect.width());
		return (height / fCellHeight);
	} else {
		return fNumberOfRows;
	}
}
Ejemplo n.º 20
0
int ContainerAreaLayout::widthForHeightR(int h) const
{
    if (orientation() == Horizontal)
    {
        return widthForHeight(h);
    }
    else
    {
        return heightForWidth(h);
    }
}
Ejemplo n.º 21
0
// QMenuBar's sizeHint() gives wrong size (insufficient width), which causes wrapping in the kicker applet
QSize KMenuBar::sizeHint() const
{
    if(!d->topLevel || block_resize > 0)
        return QMenuBar::sizeHint();
    // Since QMenuBar::sizeHint() may indirectly call resize(),
    // avoid infinite recursion.
    ++block_resize;
    // find the minimum useful height, and enlarge the width until the menu fits in that height (one row)
    int h = heightForWidth(1000000);
    int w = QMenuBar::sizeHint().width();
    // optimization - don't call heightForWidth() too many times
    while(heightForWidth(w + 12) > h)
        w += 12;
    while(heightForWidth(w + 4) > h)
        w += 4;
    while(heightForWidth(w) > h)
        ++w;
    --block_resize;
    return QSize(w, h);
}
Ejemplo n.º 22
0
QPixmap LinkDisplay::feedbackPixmap(int width, int height, const QColorGroup &colorGroup, bool isDefaultColor)
{
	int theWidth  = qMin(width, maxWidth());
	int theHeight = qMin(height, heightForWidth(theWidth));
	QPixmap pixmap(theWidth, theHeight);
	pixmap.fill(colorGroup.background());
	QPainter painter(&pixmap);
	paint(&painter, 0, 0, theWidth, theHeight, colorGroup, isDefaultColor,
	      /*isSelected=*/false, /*isHovered=*/false, /*isIconButtonHovered=*/false);
	painter.end();
	return pixmap;
}
Ejemplo n.º 23
0
QPixmap LinkDisplay::feedbackPixmap(qreal width, qreal height, const QPalette &palette, bool isDefaultColor)
{
    qreal theWidth  = qMin(width, maxWidth());
    qreal theHeight = qMin(height, heightForWidth(theWidth));
    QPixmap pixmap(theWidth, theHeight);
    pixmap.fill(palette.color(QPalette::Active, QPalette::Background));
    QPainter painter(&pixmap);
    paint(&painter, 0, 0, theWidth, theHeight, palette, isDefaultColor,
          /*isSelected=*/false, /*isHovered=*/false, /*isIconButtonHovered=*/false);
    painter.end();
    return pixmap;
}
Ejemplo n.º 24
0
QSize ContainerAreaLayout::minimumSize() const
{
    const int size = KickerLib::sizeValue(KPanelExtension::SizeTiny);

    if (orientation() == Horizontal)
    {
        return QSize(widthForHeight(size), size);
    }
    else
    {
        return QSize(size, heightForWidth(size));
    }
}
Ejemplo n.º 25
0
int QLayout::totalHeightForWidth( int w ) const
{
    if ( topLevel ) {
	QWidget *mw = (QWidget*)parent();
	if ( mw && !mw->testWState(WState_Polished) ) {
	    mw->polish();
	}
    }
    int b = (topLevel && !marginImpl) ? 2*outsideBorder : 0;
    int h = heightForWidth( w - b ) + b;
#ifndef QT_NO_MENUBAR
    if ( menubar && !menubar->isTopLevel() )
	h += menubar->heightForWidth( w );
#endif
    return h;
}
Ejemplo n.º 26
0
PatchSaveDialog::PatchSaveDialog(QString savePathStr, QString patchPathStr, qReal::Repairer *repairer)
{
	mRepairer = repairer;

	layout = new QGridLayout();
	savePath = new QLineEdit(savePathStr);
	patchPath = new QLineEdit(patchPathStr);
	saveError = new QLabel(tr("Path is incorrect"));
	patchError = new QLabel(tr("Path is incorrect"));
	saveBrowse = new QPushButton(tr("Browse"));
	patchBrowse = new QPushButton(tr("Browse"));
	saveCaption = new QLabel(tr("Path to save: "));
	patchCaption = new QLabel(tr("Path to patch: "));
	commonLabel = new QLabel(tr("Choose paths to save and patch"));
	runButton = new QPushButton(tr("Patch"));

	saveError->setStyleSheet("QLabel {color : red; }");
	patchError->setStyleSheet("QLabel {color : red; }");

	connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
	connect(this, SIGNAL(destroyed()), this, SLOT(releaseMemory()));
	connect(patchBrowse, SIGNAL(clicked()), this, SLOT(openPatchFile()));
	connect(saveBrowse, SIGNAL(clicked()), this, SLOT(openSaveDirectory()));
	connect(savePath, SIGNAL(editingFinished()), this, SLOT(checkSavePath()));
	connect(patchPath, SIGNAL(editingFinished()), this, SLOT(checkPatchPath()));

	layout->addWidget(commonLabel,0,0,1,-1,Qt::AlignLeft);
	layout->addWidget(saveCaption,1,0);
	layout->addWidget(savePath,1,1);
	layout->addWidget(saveBrowse,1,2);
	layout->addWidget(saveError,2,1,1,-1,Qt::AlignLeft);
	layout->addWidget(patchCaption,3,0);
	layout->addWidget(patchPath,3,1);
	layout->addWidget(patchBrowse,3,2);
	layout->addWidget(patchError,4,1,1,-1,Qt::AlignLeft);
	layout->addWidget(runButton,5,0,1,-1,Qt::AlignRight);

	saveError->hide();
	patchError->hide();

	setLayout(layout);

	int width = this->width();
	setFixedSize(width,heightForWidth(width));
}
Ejemplo n.º 27
0
// Description:  Returns the size hint of the layout, which, depending on the
//                layout settings, is either based on the set number of columns/rows
//                or the current width of the layout.
//
QSize KxGridLayout::sizeHint() const
{
    int width = 0;
	int height = 0;
	
	if(fColumnsResizable) {
		width = parentWidget()->width();
	} else {
		width = fNumberOfColumns * fCellWidth;
	}

	if(fAutoGrow) {
		height = heightForWidth(width);
	} else {
		height = fNumberOfRows * fCellHeight;
	}

	return QSize(width, height);
}
Ejemplo n.º 28
0
void KMenuBar::selectionTimeout()
{ // nobody is managing us, handle resizing
    if(d->topLevel)
    {
        d->fallback_mode = true; // KMenuBar is handling its position itself
        KConfigGroup xineramaConfig(KGlobal::config(), "Xinerama");
        int screen = xineramaConfig.readNumEntry("MenubarScreen", QApplication::desktop()->screenNumber(QPoint(0, 0)));
        QRect area = QApplication::desktop()->screenGeometry(screen);
        int margin = 0;
        move(area.left() - margin, area.top() - margin);
        setFixedSize(area.width() + 2 * margin, heightForWidth(area.width() + 2 * margin));
#ifdef Q_WS_X11
        int strut_height = height() - margin;
        if(strut_height < 0)
            strut_height = 0;
        KWin::setStrut(winId(), 0, 0, strut_height, 0);
#endif
    }
}
Ejemplo n.º 29
0
PaletteCell* Palette::append(Element* s, const QString& name, QString tag, qreal mag)
      {
      if (s == 0) {
            cells.append(0);
            return 0;
            }
      PaletteCell* cell = new PaletteCell;
      int idx;
      if (_moreElements) {
            idx = cells.size()-2;
            cells.insert(cells.size()-1, cell);
            }
      else {
            cells.append(cell);
            idx = cells.size() - 1;
            }
      PaletteCell* pc = add(idx, s, name, tag, mag);
      setFixedHeight(heightForWidth(width()));
      updateGeometry();
      return pc;
      }
Ejemplo n.º 30
0
int DhQGLWidget::DvhheightForWidth(int x1) const {
  return heightForWidth(x1);
}