void RenderThemeQt::adjustSliderThumbSize(RenderObject* o) const
{
    ControlPart part = o->style()->appearance();

    if (part == MediaSliderThumbPart) {
        RenderStyle* parentStyle = o->parent()->style();
        Q_ASSERT(parentStyle);

        int parentHeight = parentStyle->height().value();
        o->style()->setWidth(Length(parentHeight / 3, Fixed));
        o->style()->setHeight(Length(parentHeight, Fixed));
    } else if (part == MediaVolumeSliderThumbPart) {
        RenderStyle* parentStyle = o->parent()->style();
        Q_ASSERT(parentStyle);

        int parentWidth = parentStyle->width().value();
        o->style()->setHeight(Length(parentWidth / 3, Fixed));
        o->style()->setWidth(Length(parentWidth, Fixed));
    } else if (part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart) {
        QStyleOptionSlider option;
        if (part == SliderThumbVerticalPart)
            option.orientation = Qt::Vertical;

        QStyle* style = qStyle();

        int width = style->pixelMetric(QStyle::PM_SliderLength, &option);
        int height = style->pixelMetric(QStyle::PM_SliderThickness, &option);
        o->style()->setWidth(Length(width, Fixed));
        o->style()->setHeight(Length(height, Fixed));
    }
}
Exemple #2
0
void FormWindowData::fromFormWindow(FormWindowBase* fw)
{
    defaultMargin =  defaultSpacing = INT_MIN;
    fw->layoutDefault(&defaultMargin, &defaultSpacing);

    QStyle *style = fw->formContainer()->style();
    layoutDefaultEnabled = defaultMargin != INT_MIN || defaultMargin != INT_MIN;
    if (defaultMargin == INT_MIN)
        defaultMargin = style->pixelMetric(QStyle::PM_DefaultChildMargin, 0);
    if (defaultSpacing == INT_MIN)
        defaultSpacing = style->pixelMetric(QStyle::PM_DefaultLayoutSpacing, 0);


    marginFunction.clear();
    spacingFunction.clear();
    fw->layoutFunction(&marginFunction, &spacingFunction);
    layoutFunctionsEnabled = !marginFunction.isEmpty() || !spacingFunction.isEmpty();

    pixFunction = fw->pixmapFunction();

    author = fw->author();

    includeHints = fw->includeHints();
    includeHints.removeAll(QString());

    hasFormGrid = fw->hasFormGrid();
    grid = hasFormGrid ? fw->designerGrid() : FormWindowBase::defaultDesignerGrid();
}
QtopiaCLItemDelegate::QtopiaCLItemDelegate(QObject *parent)
    : QtopiaItemDelegate(parent),
    m_min_buddy_height(0), m_vmargin(0), m_hspace(0)
{
  m_tree_view = qobject_cast<QTreeView *>(parent);
  
  if (m_tree_view)
  {
    QStyle *st = m_tree_view->style();
    m_vmargin = st->pixelMetric(QStyle::PM_FocusFrameVMargin);
    m_min_buddy_height = st->pixelMetric(QStyle::PM_ListViewIconSize) + 2*m_vmargin;
    m_hspace = st->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  }

  accountFont = QApplication::font();
  accountFont.setPointSize(accountFont.pointSize()+2);
  accountFont.setUnderline(true);
  accountFont.setBold(true);

  groupFont = QApplication::font();
  groupFont.setPointSize(groupFont.pointSize()+2);

  separatorFont = QApplication::font();
  separatorFont.setItalic(true);


  firstLineFont = QApplication::font();
  firstLineFont.setPointSize(firstLineFont.pointSize()+1);

  secondLineFont = QApplication::font();
  secondLineFont.setPointSize(secondLineFont.pointSize()-1);
}
Exemple #4
0
/*!
  \brief Gets the suitable size of project window.
  This size is just suitable for the whole project area with 1px border and
  the scroll bar.
  \return suitable size of this project window
 */
QSize Ui::ProjectWindow::sizeHint() const
{
    QStyle *style = qApp->style();
    int frameBorderWidth = style->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth);
    int frameTitleHeight = style->pixelMetric(QStyle::PM_TitleBarHeight);
    int scrollBarWidth = style->pixelMetric(QStyle::PM_ScrollBarExtent);
    return QSize(view->width() + (frameBorderWidth << 1) + scrollBarWidth + 2,
                 view->height() + frameTitleHeight + frameBorderWidth + statusBar->height() - 10);
}
void QToolBarLayout::updateMarginAndSpacing()
{
    QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
    if (!tb)
        return;
    QStyle *style = tb->style();
    QStyleOptionToolBar opt;
    tb->initStyleOption(&opt);
    setMargin(style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb)
                + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb));
    setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, tb));
}
void StatusBarLayout::updateMarginAndSpacing()
{
    Statusbar* statusBar = qobject_cast<Statusbar*>( parentWidget() );
    if( ! statusBar )
        return;

    QStyle* style = statusBar->style();
    QStyleOptionToolBar opt;
    statusBar->initStyleOption( &opt );
    setMargin( style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, statusBar)
                + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, statusBar) );
    setSpacing( style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, statusBar) );
}
Exemple #7
0
/**
 * @todo enable eliding (use QFontMetrics::elidedText() )
 */
void bicItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
  QStyleOptionViewItem opt = option;
  initStyleOption(&opt, index);

  // Background
  QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

  const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
  const QRect textArea = QRect(opt.rect.x() + margin, opt.rect.y() + margin, opt.rect.width() - 2 * margin, opt.rect.height() - 2 * margin);

  // Paint name
  painter->save();
  QFont smallFont = getSmallFont(opt);
  QFontMetrics metrics(opt.font);
  QFontMetrics smallMetrics(smallFont);
  QRect nameRect = style->alignedRect(opt.direction, Qt::AlignBottom, QSize(textArea.width(), smallMetrics.lineSpacing()), textArea);
  painter->setFont(smallFont);
  style->drawItemText(painter, nameRect, Qt::AlignBottom, QApplication::palette(), true, index.model()->data(index, bicModel::InstitutionNameRole).toString(), option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Mid);
  painter->restore();

  // Paint BIC
  painter->save();
  QFont normal = painter->font();
  normal.setBold(true);
  painter->setFont(normal);
  QRect bicRect = style->alignedRect(opt.direction, Qt::AlignTop, QSize(textArea.width(), metrics.lineSpacing()), textArea);
  const QString bic = index.model()->data(index, Qt::DisplayRole).toString();
  style->drawItemText(painter, bicRect, Qt::AlignTop, QApplication::palette(), true, bic, option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);

  painter->restore();
}
void QToolBarPrivate::init()
{
    Q_Q(QToolBar);
    q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
    q->setBackgroundRole(QPalette::Button);
    q->setAttribute(Qt::WA_Hover);
    q->setAttribute(Qt::WA_X11NetWmWindowTypeToolBar);

    QStyle *style = q->style();
    int e = style->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q);
    iconSize = QSize(e, e);

    layout = new QToolBarLayout(q);
    layout->updateMarginAndSpacing();

#ifdef Q_WS_MAC
    if (q->parentWidget() && q->parentWidget()->isWindow()) {
        // Make sure that the window has the "toolbar" button.
        QWidget *parentWidget = q->parentWidget();
        qt_mac_updateToolBarButtonHint(parentWidget);
        reinterpret_cast<QToolBar *>(parentWidget)->d_func()->createWinId(); // Please let me create your winId...
        extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp
        macWindowToolbarShow(q->parentWidget(), true);
    }
#endif

    toggleViewAction = new QAction(q);
    toggleViewAction->setCheckable(true);
    q->setMovable(q->style()->styleHint(QStyle::SH_ToolBar_Movable, 0, q ));
    QObject::connect(toggleViewAction, SIGNAL(triggered(bool)), q, SLOT(_q_toggleView(bool)));
}
Exemple #9
0
void PhotoDelegate::paint(
        QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QPen oldPen = painter->pen();

    QStyle *style = QApplication::style();

    int margin = style->pixelMetric(QStyle::PM_ButtonMargin);

    QRect rect = option.rect;

    if (option.state & QStyle::State_HasFocus) {
        painter->fillRect(rect, option.palette.highlight());

        painter->setPen(option.palette.color(QPalette::HighlightedText));
    }

    rect.adjust(margin, margin, -margin, -margin);

    QRect decorationRect = rect;
    decorationRect.setRight(decorationRect.left() + option.decorationSize.width());

    QPixmap decoration = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole));
    if (!decoration.isNull())
        style->drawItemPixmap(painter, decorationRect, Qt::AlignCenter, decoration);
    else
        painter->drawRect(decorationRect);

    painter->setPen(oldPen);
}
Exemple #10
0
QSize SearchItemDelegate::sizeHint(const QStyleOptionViewItem &option,
                                   const QModelIndex &index) const
{
    QStyleOptionViewItem opt(option);

    QStyle *style = opt.widget->style();

    QSize size = QStyledItemDelegate::sizeHint(opt, index);
    size.setWidth(0);

    const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, &opt, opt.widget) + 1;

    // Find decoration roles with data present.
    QList<int> roles;
    for (int role : m_decorationRoles) {
        if (!index.data(role).isNull())
            roles.append(role);
    }

    if (!roles.isEmpty()) {
        const QIcon icon = index.data(roles.first()).value<QIcon>();
        const QSize actualSize = icon.actualSize(opt.decorationSize);
        const int decorationWidth = std::min(opt.decorationSize.width(), actualSize.width());
        size.rwidth() = (decorationWidth + margin) * roles.size() + margin;
    }

    size.rwidth() += opt.fontMetrics.width(index.data().toString()) + margin * 2;
    return size;
}
//-----------------------------------------------------------------------------
qtConfirmationDialog::qtConfirmationDialog(
  const QString& askKey, QWidget* parent, Qt::WindowFlags flags)
  : QDialog(parent, flags), d_ptr(new qtConfirmationDialogPrivate)
{
  QTE_D(qtConfirmationDialog);

  d->AskKey = askKey;

  // Create UI
  d->UI.setupUi(this);
  this->setConfirmText("Continue");
  qtUtil::setStandardIcons(d->UI.buttonBox);

  // Set dialog icon
  QStyle* style = this->style();
  int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
  QIcon icon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, this);
  QPixmap pixmap = icon.pixmap(iconSize, iconSize);
  d->UI.image->setPixmap(pixmap);
  d->UI.image->setFixedSize(pixmap.size());

  // Hide unneeded "don't ask" controls
  d->UI.noAsk->setHidden(askKey.isEmpty());
  d->UI.noAskSession->hide();
  d->UI.noAskEver->hide();
}
Exemple #12
0
NS_IMETHODIMP
nsNativeThemeQt::ThemeChanged()
{
    QStyle *s = qApp->style();
    if (s)
        mFrameWidth = s->pixelMetric(QStyle::PM_DefaultFrameWidth);
    return NS_OK;
}
Exemple #13
0
/** @todo elide texts */
void ibanBicItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QStyleOptionViewItem opt = option;
    initStyleOption(&opt, index);

    // Background
    QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

    const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
    const QRect textArea = QRect(opt.rect.x() + margin, opt.rect.y() + margin, opt.rect.width() - 2 * margin, opt.rect.height() - 2 * margin);

    // Do not paint text if the edit widget is shown
    const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(opt.widget);
    if (view && view->indexWidget(index))
        return;

    // Get data
    payeeIdentifierTyped<payeeIdentifiers::ibanBic> ibanBic = ibanBicByIndex(index);

    // Paint Bic
    painter->save();
    const QFont smallFont = painter->font();
    const QFontMetrics metrics(opt.font);
    const QFontMetrics smallMetrics(smallFont);
    const QRect bicRect = style->alignedRect((opt.direction  == Qt::RightToLeft) ? Qt::LeftToRight : Qt::RightToLeft, Qt::AlignTop, QSize(textArea.width(), smallMetrics.lineSpacing()),
                          QRect(textArea.left(), metrics.lineSpacing() + textArea.top(), textArea.width(), smallMetrics.lineSpacing())
                                            );
    painter->setFont(smallFont);
    style->drawItemText(painter, bicRect, Qt::AlignBottom | Qt::AlignRight, QApplication::palette(), true, ibanBic->storedBic(), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();

    // Paint Bank name
    painter->save();
    const QRect nameRect = style->alignedRect(opt.direction, Qt::AlignTop, QSize(textArea.width(), smallMetrics.lineSpacing()),
                           QRect(textArea.left(), metrics.lineSpacing() + textArea.top(), textArea.width(), smallMetrics.lineSpacing())
                                             );
    style->drawItemText(painter, nameRect, Qt::AlignBottom, QApplication::palette(), true, ibanBic->institutionName(), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();

    // Paint IBAN
    painter->save();
    QFont normal = painter->font();
    normal.setBold(true);
    painter->setFont(normal);
    const QRect ibanRect = style->alignedRect(opt.direction, Qt::AlignTop, QSize(textArea.width(), metrics.lineSpacing()), textArea);
    const QString bic = index.model()->data(index, Qt::DisplayRole).toString();
    style->drawItemText(painter, ibanRect, Qt::AlignTop, QApplication::palette(), true, ibanBic->paperformatIban(), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();

    // Paint type
    painter->save();
    QRect typeRect = style->alignedRect(opt.direction, Qt::AlignTop | Qt::AlignRight, QSize(textArea.width() / 5, metrics.lineSpacing()), textArea);
    style->drawItemText(painter, typeRect, Qt::AlignTop | Qt::AlignRight, QApplication::palette(), true, i18n("IBAN & BIC"), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();
}
int PlatformScrollbar::horizontalScrollbarHeight(ScrollbarControlSize controlSize)
{
    QStyle *s = QApplication::style();
    QStyleOptionSlider o;
    o.orientation = Qt::Horizontal;
    o.state |= QStyle::State_Horizontal;
    if (controlSize != RegularScrollbar)
        o.state |= QStyle::State_Mini;
    return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0);
}
Exemple #15
0
int ScrollbarThemeQt::scrollbarThickness(ScrollbarControlSize controlSize)
{
    QStyle* s = QApplication::style();
    QStyleOptionSlider o;
    o.orientation = Qt::Vertical;
    o.state &= ~QStyle::State_Horizontal;
    if (controlSize != RegularScrollbar)
        o.state |= QStyle::State_Mini;
    return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0);
}
Exemple #16
0
void AlbumDelegate::paint(
        QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QPen oldPen = painter->pen();

    QStyle *style = QApplication::style();

    int margin = style->pixelMetric(QStyle::PM_ButtonMargin);

    QRect rect = option.rect;

    if (option.state & QStyle::State_HasFocus) {
        painter->fillRect(rect, option.palette.highlight());

        painter->setPen(option.palette.color(QPalette::HighlightedText));
    }

    rect.adjust(margin, margin, -margin, -margin);

    QRect decorationRect = rect;
    decorationRect.setRight(decorationRect.left() + option.decorationSize.width());

    QPixmap decoration = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole));
    if (!decoration.isNull())
        style->drawItemPixmap(painter, decorationRect, Qt::AlignCenter, decoration);
    else
        painter->drawRect(decorationRect);

    rect.setLeft(decorationRect.right() + margin);

    QString text = index.data(Qt::DisplayRole).toString();

    QRect textRect;
    painter->drawText(rect, Qt::TextWordWrap, text, &textRect);
    rect.setTop(textRect.bottom() + margin);

    text = index.data(Artist).toString();

    painter->drawText(rect, Qt::TextWordWrap, text, &textRect);
    rect.setTop(textRect.bottom() + margin);

    QVariant trackCount = index.data(TrackCount);

    if (trackCount.isValid()) {
        text = trackCount.toInt() != 1
                ? tr("%1 Songs").arg(trackCount.toInt())
                : tr("1 Song");

        painter->drawText(rect, Qt::TextWordWrap, text, &textRect);
    }

    painter->setPen(oldPen);
}
Exemple #17
0
void RenderThemeQStyle::adjustSliderThumbSize(RenderStyle* style) const
{
    const ControlPart part = style->appearance();
    if (part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart) {
        QStyleOptionSlider option;
        if (part == SliderThumbVerticalPart)
            option.orientation = Qt::Vertical;

        QStyle* qstyle = qStyle();

        int length = qstyle->pixelMetric(QStyle::PM_SliderLength, &option);
        int thickness = qstyle->pixelMetric(QStyle::PM_SliderThickness, &option);
        if (option.orientation == Qt::Vertical) {
            style->setWidth(Length(thickness, Fixed));
            style->setHeight(Length(length, Fixed));
        } else {
            style->setWidth(Length(length, Fixed));
            style->setHeight(Length(thickness, Fixed));
        }
    } else
        RenderThemeQt::adjustSliderThumbSize(style);
}
Exemple #18
0
ShutdownPrompt::ShutdownPrompt( QWidget *parent ) :
	QDialog( parent ),
	ui( new Ui::ShutdownPrompt ) {
	ui->setupUi( this );

	QStyle *style = this->style();
	int iconSize = style->pixelMetric( QStyle::PM_MessageBoxIconSize, 0, this );

	QIcon tmpIcon = style->standardIcon( QStyle::SP_MessageBoxQuestion, 0, this );

	ui->iconLabel->setPixmap( tmpIcon.pixmap( iconSize, iconSize ) );

	connect( ui->remember, SIGNAL( clicked() ), this, SLOT( remember() ) );
	connect( ui->dontRemember, SIGNAL( clicked() ), this, SLOT( dontRemember() ) );
}
static QSize viewItemTextSize ( const QStyleOptionViewItemV4 *option )
{
	QStyle *style = option->widget ? option->widget->style() : QApplication::style();
	QTextOption textOption;
	textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere );
	QTextLayout textLayout;
	textLayout.setTextOption ( textOption );
	textLayout.setFont ( option->font );
	textLayout.setText ( option->text );
	const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, option, option->widget ) + 1;
	QRect bounds ( 0,0,100 - 2*textMargin,600 );
	qreal height = 0, widthUsed = 0;
	viewItemTextLayout ( textLayout, bounds.width(), height, widthUsed );
	const QSize size ( qCeil ( widthUsed ), qCeil ( height ) );
	return QSize ( size.width() + 2 * textMargin, size.height() );
}
QTransferFunctionEditorByValues::QTransferFunctionEditorByValues(QWidget *parent)
 : QTransferFunctionEditor(parent)
{
    setupUi(this);

    // Creem una scroll area per si hi ha molts intervals (no es pot crear des del Qt Designer)

    QScrollArea *scrollArea = new QScrollArea(this);
    qobject_cast<QBoxLayout*>(this->layout())->insertWidget(1, scrollArea);

    m_intervalEditorsWidget = new QWidget(scrollArea);
    QBoxLayout *layout = new QVBoxLayout(m_intervalEditorsWidget);
    m_intervalEditorsLayout = new QVBoxLayout();
    layout->addLayout(m_intervalEditorsLayout);
    layout->addStretch();
    layout->setMargin(0);

    scrollArea->setWidget(m_intervalEditorsWidget);
    scrollArea->setWidgetResizable(true);
    scrollArea->setFrameShape(QFrame::NoFrame);

    // Creem el primer interval

    QTransferFunctionIntervalEditor *first = new QTransferFunctionIntervalEditor(m_intervalEditorsWidget);
    first->setIsFirst(true);
    first->setIsLast(true);
    first->setObjectName("interval0");
    m_intervalEditorsLayout->addWidget(first);

    connect(first, SIGNAL(startChanged(int)), SLOT(markAsChanged()));
    connect(first, SIGNAL(endChanged(int)), SLOT(markAsChanged()));
    connect(first, SIGNAL(colorChanged(const QColor&)), SLOT(markAsChanged()));

    // Mida mínima de la scroll area
    QStyle *style = scrollArea->style();
    int scrollBarWidth = style->pixelMetric(QStyle::PM_ScrollBarExtent);
    scrollArea->setMinimumWidth(first->minimumSizeHint().width() + scrollBarWidth);

    m_numberOfIntervals = 1;

    m_changed = true;

    connect(m_addPushButton, SIGNAL(clicked()), SLOT(addInterval()));
    connect(m_removePushButton, SIGNAL(clicked()), SLOT(removeInterval()));
    connect(m_nameLineEdit, SIGNAL(textChanged(const QString&)), SLOT(markAsChanged()));
}
int
PrettyItemDelegate::headerHeight() const
{
    int headRows = LayoutManager::instance()->activeLayout().layoutForPart( PlaylistLayout::Head ).rows();

    if( headRows < 1 )
        return 0;

    QStyle *style;
    if( QWidget *w = qobject_cast<QWidget*>(parent()) )
        style = w->style();
    else
        style = QApplication::style();

    int frameVMargin = style->pixelMetric( QStyle::PM_FocusFrameVMargin );
    return headRows * ( s_fontHeight + frameVMargin );
}
Exemple #22
0
void KPageListViewDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
  if ( !index.isValid() )
    return;

  QStyleOptionViewItemV4 opt(option);
  opt.showDecorationSelected = true;
  QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();

  int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize);
  const QString text = index.model()->data( index, Qt::DisplayRole ).toString();
  const QIcon icon = index.model()->data( index, Qt::DecorationRole ).value<QIcon>();
  const QPixmap pixmap = icon.pixmap( iconSize, iconSize );

  QFontMetrics fm = painter->fontMetrics();
  int wp = pixmap.width();
  int hp = pixmap.height();

  QTextLayout iconTextLayout( text, option.font );
  QTextOption textOption( Qt::AlignHCenter );
  iconTextLayout.setTextOption( textOption );
  int maxWidth = qMax( 3 * wp, 8 * fm.height() );
  layoutText( &iconTextLayout, maxWidth );

  QPen pen = painter->pen();
  QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
                            ? QPalette::Normal : QPalette::Disabled;
  if ( cg == QPalette::Normal && !(option.state & QStyle::State_Active) )
    cg = QPalette::Inactive;

  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
  if ( option.state & QStyle::State_Selected ) {
    painter->setPen( option.palette.color( cg, QPalette::HighlightedText ) );
  } else {
    painter->setPen( option.palette.color( cg, QPalette::Text ) );
  }

  painter->drawPixmap( option.rect.x() + (option.rect.width()/2)-(wp/2), option.rect.y() + 5, pixmap );
  if ( !text.isEmpty() )
    iconTextLayout.draw( painter, QPoint( option.rect.x() + (option.rect.width()/2)-(maxWidth/2), option.rect.y() + hp+7 ) );

  painter->setPen( pen );

  drawFocus( painter, option, option.rect );
}
QSize ListViewDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
	QStyleOptionViewItemV4 opt = option;
	initStyleOption ( &opt, index );
	opt.features |= QStyleOptionViewItem::WrapText;
	opt.text = index.data().toString();
	opt.textElideMode = Qt::ElideRight;
	opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter;

	QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
	const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, &option, opt.widget ) + 1;
	int height = 48 + textMargin * 2 + 5; // TODO: turn constants into variables
	QSize szz = viewItemTextSize ( &opt );
	height += szz.height();
	// FIXME: maybe the icon items could scale and keep proportions?
	QSize sz ( 100,height );
	return sz;
}
Exemple #24
0
PRectangle ListBoxImpl::GetDesiredRect()
{
	ListWidget *list = static_cast<ListWidget *>(wid);

	int rows = Length();
	if (rows == 0 || rows > visibleRows) {
		rows = visibleRows;
	}
	int rowHeight = list->sizeHintForRow(0);
	int height = (rows * rowHeight) + (2 * list->frameWidth());

	QStyle *style = QApplication::style();
	int width = list->sizeHintForColumn(0) + (2 * list->frameWidth());
	if (Length() > rows) {
		width += style->pixelMetric(QStyle::PM_ScrollBarExtent);
	}

	return PRectangle(0, 0, width, height);
}
void CMessageDialog::initializeUi( QMessageBox::Icon iconStyle ) {
  ui->setupUi(this);
  ui->label_2->setFrameShape( QFrame::NoFrame );

  connect( ui->btnOK, SIGNAL( clicked() ), this, SLOT( close() ) );
  connect( ui->btnCopy, SIGNAL( clicked() ), this, SLOT( copyToClipboard() ) );
  connect( ui->btnSave, SIGNAL( clicked() ), this, SLOT( save() ) );

  QMessageBox* mb = new QMessageBox();

  QStyle *style = mb ? mb->style() : QApplication::style();

  QIcon tmpIcon;

  switch( iconStyle ) {
    case QMessageBox::NoIcon:
      // Do nothing
      break;
    case QMessageBox::Information:
      tmpIcon = style->standardIcon( QStyle::SP_MessageBoxInformation );
      break;
    case QMessageBox::Warning:
      tmpIcon = style->standardIcon( QStyle::SP_MessageBoxWarning );
      break;
    case QMessageBox::Critical:
      tmpIcon = style->standardIcon( QStyle::SP_MessageBoxCritical );
      break;
    case QMessageBox::Question:
      tmpIcon = style->standardIcon( QStyle::SP_MessageBoxQuestion );
      break;
  }

  if( tmpIcon.isNull() )
    ui->label_2->setGeometry( ui->label_2->x(), ui->label_2->y(), 0, 0 );
  else {
    int iconSize = style->pixelMetric( QStyle::PM_MessageBoxIconSize, 0, mb );
    ui->label_2->setGeometry( ui->label_2->x(), ui->label_2->y(), iconSize, iconSize );
    ui->label_2->setPixmap( tmpIcon.pixmap( iconSize, iconSize ) );
  }

  delete mb;
}
Exemple #26
0
void QToolBarPrivate::init()
{
    Q_Q(QToolBar);
    q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
    q->setBackgroundRole(QPalette::Button);
    q->setAttribute(Qt::WA_Hover);
    q->setAttribute(Qt::WA_X11NetWmWindowTypeToolBar);

    QStyle *style = q->style();
    int e = style->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q);
    iconSize = QSize(e, e);

    layout = new QToolBarLayout(q);
    layout->updateMarginAndSpacing();

    toggleViewAction = new QAction(q);
    toggleViewAction->setCheckable(true);
    q->setMovable(q->style()->styleHint(QStyle::SH_ToolBar_Movable, 0, q ));
    QObject::connect(toggleViewAction, SIGNAL(triggered(bool)), q, SLOT(_q_toggleView(bool)));
}
Exemple #27
0
QPixmap TimedMessageBox::getIcon(TimedMessageBox::Icons icon)
{
    QStyle *style = this ? this->style() : QApplication::style();
    int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
    QIcon tmpIcon;
    switch (icon) {
    case Infomation:
    tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, this);
    break;
    case Warning:
    tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, this);
    break;
    case Critical:
    tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, this);
    break;
    }
    if (!tmpIcon.isNull())
        return tmpIcon.pixmap(iconSize, iconSize);
    return QPixmap();
}
Exemple #28
0
QSize KPageListViewDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
  if ( !index.isValid() )
    return QSize( 0, 0 );

  QStyleOptionViewItemV4 opt(option);
  opt.showDecorationSelected = true;
  QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();

  int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize);
  const QString text = index.model()->data( index, Qt::DisplayRole ).toString();
  const QIcon icon = index.model()->data( index, Qt::DecorationRole ).value<QIcon>();
  const QPixmap pixmap = icon.pixmap( iconSize, iconSize );

  QFontMetrics fm = option.fontMetrics;
  int gap = fm.height();
  int wp = pixmap.width();
  int hp = pixmap.height();

  if ( hp == 0 ) {
    /**
     * No pixmap loaded yet, we'll use the default icon size in this case.
     */
    hp = iconSize;
    wp = iconSize;
  }

  QTextLayout iconTextLayout( text, option.font );
  int wt = layoutText( &iconTextLayout, qMax( 3 * wp, 8 * fm.height() ) );
  int ht = iconTextLayout.boundingRect().height();

  int width, height;
  if ( text.isEmpty() )
    height = hp;
  else
    height = hp + ht + 10;

  width = qMax( wt, wp ) + gap;

  return QSize( width, height );
}
int QDecorationStyled::titleBarHeight(const QWidget *widget)
{
    QStyleOptionTitleBar opt;
    opt.subControls = QStyle::SC_TitleBarLabel
                      | QStyle::SC_TitleBarSysMenu
                      | QStyle::SC_TitleBarNormalButton
                      | QStyle::SC_TitleBarContextHelpButton
                      | QStyle::SC_TitleBarMinButton
                      | QStyle::SC_TitleBarMaxButton
                      | QStyle::SC_TitleBarCloseButton;
    opt.titleBarFlags = widget->windowFlags();
    opt.direction = QApplication::layoutDirection();
    opt.text = windowTitleFor(widget);
    opt.icon = widget->windowIcon();
    opt.rect = widget->rect();

    QStyle *style = QApplication::style();
    if (!style)
        return 18;

    return style->pixelMetric(QStyle::PM_TitleBarHeight, &opt, 0);
}
Exemple #30
0
NS_IMETHODIMP
nsNativeThemeQt::GetWidgetBorder(nsDeviceContext* ,
                                 nsIFrame* aFrame,
                                 PRUint8 aWidgetType,
                                 nsIntMargin* aResult)
{
    (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = 0;

    QStyle* style = qApp->style();
    switch(aWidgetType) {
//     case NS_THEME_TEXTFIELD:
//     case NS_THEME_LISTBOX:
    case NS_THEME_MENUPOPUP: {
        (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = style->pixelMetric(QStyle::PM_MenuPanelWidth);
        break;
    }
    default:
        break;
    }

    return NS_OK;
}