void QtCurveShadowConfiguration::setColorType(ColorType ct)
{
    m_colorType=ct;
    switch(m_colorType)
    {
        default:
        case CT_FOCUS:
            m_color = KColorScheme(m_colorGroup).decoration(KColorScheme::FocusColor).color();
            break;
        case CT_HOVER:
            m_color = KColorScheme(m_colorGroup).decoration(KColorScheme::HoverColor).color();
            break;
        case CT_SELECTION:
            m_color = QApplication::palette().color(m_colorGroup, QPalette::Highlight);
            break;
        case CT_TITLEBAR:
            m_color = QPalette::Active==m_colorGroup
                        ? KGlobalSettings::activeTitleColor()
                        : KGlobalSettings::inactiveTitleColor();
            break;
        case CT_GRAY:
            m_color = QColor("#393835");
            break;
        case CT_CUSTOM:
            break;
    }
}
Beispiel #2
0
void QueryWidget::findInPage(bool forward)
{
	if(!m_find->isVisible())
		showSearch();

	QWebPage::FindFlags flags = QWebPage::FindWrapsAroundDocument;
	if(m_findui->casesensitive->isChecked())
		flags |= QWebPage::FindCaseSensitively;
	if(m_findui->highlightall->isChecked())
		flags |= QWebPage::HighlightAllOccurrences;
	if(!forward)
		flags |= QWebPage::FindBackward;

	QBrush text;
	if(m_view->findText(m_findui->findtext->text(), flags)) {
		// Found text
		text = KColorScheme(QPalette::Normal).foreground(KColorScheme::NormalText);
	} else {
		// Not found
		text = KColorScheme(QPalette::Normal).foreground(KColorScheme::NegativeText);
	}
	QPalette pal;
	pal.setBrush(QPalette::Text, text);
	m_findui->findtext->setPalette(pal);
}
Beispiel #3
0
KStartupLogo::KStartupLogo() :
    QObject(0),
    m_splash(0)
{
  // splash screen setting
  if (!KMyMoneyGlobalSettings::showSplash())
    return;

  QString filename = KGlobal::dirs()->findResource("appdata", "pics/startlogo.png");
  QString localeFilename = KGlobal::locale()->localizedFilePath(filename);
  QPixmap logoOverlay(localeFilename);

  QPixmap logoPixmap(logoOverlay.size());
  logoPixmap.fill(KColorScheme(QPalette::Active, KColorScheme::Selection).background(KColorScheme::NormalBackground).color());
  QPainter pixmapPainter(&logoPixmap);
  pixmapPainter.drawPixmap(0, 0, logoOverlay, 0, 0, logoOverlay.width(), logoOverlay.height());

  if (!logoOverlay.isNull()) {
    const KAboutData *aboutData = KCmdLineArgs::aboutData();
    KSplashScreen* splash = new KSplashScreen(logoPixmap);
    splash->setFixedSize(logoPixmap.size());

    splash->show();
    splash->showMessage(i18n("Loading %1...", aboutData->version()),  //krazy:exclude=qmethods
                        Qt::AlignLeft | Qt::AlignBottom,
                        KColorScheme(QPalette::Active, KColorScheme::Selection)
                        .foreground(KColorScheme::NormalText).color());
    m_splash = splash;
  }
}
Beispiel #4
0
QString KMyMoneyUtils::variableCSS()
{
  QColor tcolor = KColorScheme(QPalette::Active).foreground(KColorScheme::NormalText).color();
  QColor link = KColorScheme(QPalette::Active).foreground(KColorScheme::LinkText).color();

  QString css;
  css += "<style type=\"text/css\">\n<!--\n";
  css += QString(".row-even, .item0 { background-color: %1; color: %2 }\n")
         .arg((KMyMoneyGlobalSettings::listBGColor()).name()).arg(tcolor.name());
  css += QString(".row-odd, .item1  { background-color: %1; color: %2 }\n")
         .arg((KMyMoneyGlobalSettings::listColor()).name()).arg(tcolor.name());
  css += QString("a { color: %1 }\n").arg(link.name());
  css += "-->\n</style>\n";
  return css;
}
Beispiel #5
0
void TabBar::setTabHighlighted(int index)
{
    const QByteArray propertyName = highlightPropertyName(index);
    const QColor highlightColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::PositiveText).color();

    if (tabTextColor(index) != highlightColor)
    {
        if (ReKonfig::animatedTabHighlighting())
        {
            m_tabHighlightEffect->setEnabled(true);
            m_tabHighlightEffect->setProperty(propertyName, qreal(0.9));
            QPropertyAnimation *anim = new QPropertyAnimation(m_tabHighlightEffect, propertyName);
            m_highlightAnimation.insert(propertyName, anim);

            //setup the animation
            anim->setStartValue(0.9);
            anim->setEndValue(0.0);
            anim->setDuration(500);
            anim->setLoopCount(2);
            anim->start(QAbstractAnimation::DeleteWhenStopped);

            m_animationMapper->setMapping(anim, index);
            connect(anim, SIGNAL(finished()), m_animationMapper, SLOT(map()));
        }

        setTabTextColor(index, highlightColor);
    }
}
ContactListView::ContactListView(KAddressBookTableView *view,
                                 KABC::AddressBook* /* doc */,
                                 QWidget *parent,
                                 const char *name )
  : K3ListView( parent ),
    pabWidget( view ),
    oldColumn( 0 )
{
  setObjectName(name);
  mABackground = true;
  mSingleLine = false;
  mToolTips = true;
  mShowIM = true;
  mAlternateColor = KColorScheme( QPalette::Active, KColorScheme::View ).background( KColorScheme::AlternateBackground ).color();

  setAlternateBackgroundEnabled(mABackground);
  setAcceptDrops( true );
  viewport()->setAcceptDrops( true );
  setAllColumnsShowFocus( true );
  setShowSortIndicator(true);
  setSelectionModeExt( K3ListView::Extended );
  setDropVisualizer(false);
  connect(this, SIGNAL(dropped(QDropEvent*)),
          this, SLOT(itemDropped(QDropEvent*)));
}
Beispiel #7
0
QVariant SampleGroupCondition::data(const QModelIndex &index, int role) const
{
  if (!index.isValid()) return QVariant();

  Condition *rowCondition = m_sampleGroupConditions[index.row()].first;

  if (!rowCondition)
  {
    return QVariant();
  }
  else if (index.column() == 0)
  {
      if (role == Qt::DisplayRole)
          return  rowCondition->name();
      else if (role == Qt::FontRole && !rowCondition->isSatisfied())
      {
          QFont font;
          font.setItalic(true);
          return font;
      }
      else if (role == Qt::ForegroundRole && !rowCondition->isSatisfied())
          return KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText);
  }
  else if (index.column() == 1)
  {
      if (role == Qt::DisplayRole)
        return m_sampleGroupConditions.at(index.row()).second;
  }

  return QVariant();
}
//BEGIN KateStyleTreeWidget
KateStyleTreeWidget::KateStyleTreeWidget( QWidget *parent, bool showUseDefaults )
    : QTreeWidget( parent )
{
  setItemDelegate(new KateStyleTreeDelegate(this));
  setRootIsDecorated(false);

  QStringList headers;
  headers << i18nc("@title:column Meaning of text in editor", "Context") << QString() << QString() << QString() << QString() << i18nc("@title:column Text style", "Normal") << i18nc("@title:column Text style", "Selected") << i18nc("@title:column Text style", "Background") << i18nc("@title:column Text style", "Background Selected");
  if(showUseDefaults) {
    headers << i18n("Use Default Style");
  }

  setHeaderLabels(headers);

  headerItem()->setIcon(1, KIcon("format-text-bold"));
  headerItem()->setIcon(2, KIcon("format-text-italic"));
  headerItem()->setIcon(3, KIcon("format-text-underline"));
  headerItem()->setIcon(4, KIcon("format-text-strikethrough"));

  // grap the bg color, selected color and default font
  normalcol = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
  bgcol = KateRendererConfig::global()->backgroundColor();
  selcol = KateRendererConfig::global()->selectionColor();
  docfont = KateRendererConfig::global()->font();

  QPalette pal = viewport()->palette();
  pal.setColor(QPalette::Background, bgcol);
  viewport()->setPalette( pal );
}
Beispiel #9
0
void TabBar::resetTabHighlighted(int index)
{
    if (ReKonfig::animatedTabHighlighting())
        removeAnimation(index);

    setTabTextColor(index, KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::NormalText).color());
}
Beispiel #10
0
 Private( const QString& _url, KUrlLabel* _parent )
   : parent( _parent ),
     url( _url ),
     tipText( url ),
     linkColor( KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::LinkText).color() ),
     highlightedLinkColor( KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::ActiveText).color() ),
     cursor( 0 ),
     textUnderlined( true ),
     realUnderlined( true ),
     useTips( false ),
     useCursor( false ),
     glowEnabled( true ),
     floatEnabled( false ),
     timer( new QTimer( parent ) )
 {
   connect( timer, SIGNAL(timeout()), parent, SLOT(updateColor()) );
 }
Beispiel #11
0
void Bookmark::init()
{
    DEBUG_BLOCK
    QFont labelFont;
    labelFont.setPointSize( labelFont.pointSize() + 1  );
    QBrush brush = KColorScheme( QPalette::Active ).foreground( KColorScheme::NormalText );

    m_bookmarkWidget = new BookmarkManagerWidgetProxy( this );
    
    connect( The::paletteHandler(), SIGNAL( newPalette( const QPalette& ) ), SLOT(  paletteChanged( const QPalette &  ) ) );
}
Beispiel #12
0
void KateStyleTreeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
  static QSet<int> columns;
  if (!columns.count())
    columns << KateStyleTreeWidgetItem::Foreground << KateStyleTreeWidgetItem::SelectedForeground << KateStyleTreeWidgetItem::Background << KateStyleTreeWidgetItem::SelectedBackground;

  if(index.column() == KateStyleTreeWidgetItem::Context) {
    QStyleOptionViewItem styleContextItem(option);

    QBrush brush = getBrushForColorColumn(index, KateStyleTreeWidgetItem::SelectedBackground);
    if(brush != QBrush()) {
      styleContextItem.palette.setBrush(QPalette::Highlight, brush);
    } else {
      styleContextItem.palette.setBrush(QPalette::Highlight, QBrush(KateRendererConfig::global()->selectionColor()));
    }

    brush = getBrushForColorColumn(index, KateStyleTreeWidgetItem::SelectedForeground);
    if(brush != QBrush()) {
      styleContextItem.palette.setBrush(QPalette::HighlightedText, brush);
    }
	
    return QStyledItemDelegate::paint(painter, styleContextItem, index);
  }
  
  if (!columns.contains(index.column())) {
    return QStyledItemDelegate::paint(painter, option, index);
  }

  QVariant displayData = index.model()->data(index);
  if (displayData.type() != QVariant::Brush)
    return QStyledItemDelegate::paint(painter, option, index);

  QBrush brush = qVariantValue<QBrush>(displayData);

  QStyleOptionButton opt;
  opt.rect = option.rect;
  opt.palette = m_widget->palette();

  bool set = brush != QBrush();

  if (!set) {
    opt.text = i18nc("No text or background color set", "None set");
    brush = Qt::white;
  }
  
  if(index.row() == m_widget->currentIndex().row() && m_widget->currentItem()->isSelected() && m_widget->currentItem()->childCount() == 0) {
    painter->fillRect(opt.rect, KColorScheme(QPalette::Active, KColorScheme::Selection).background());
  }
  
  m_widget->style()->drawControl(QStyle::CE_PushButton, &opt, painter, m_widget);

  if (set)
    painter->fillRect(m_widget->style()->subElementRect(QStyle::SE_PushButtonContents, &opt,m_widget), brush);
}
Beispiel #13
0
PageBreakEntry::PageBreakEntry(Worksheet* worksheet)
  : WorksheetEntry(worksheet)
{
    m_msgItem = new WorksheetTextItem(this);

    QTextCursor cursor = m_msgItem->textCursor();
    KColorScheme color = KColorScheme(QPalette::Normal, KColorScheme::View);
    QTextCharFormat cformat(cursor.charFormat());
    cformat.setForeground(color.foreground(KColorScheme::InactiveText));

    cursor.insertText(i18n("--- Page Break ---"), cformat);

    setFlag(QGraphicsItem::ItemIsFocusable);
}
Beispiel #14
0
void BookmarksProtocol::echoStyle()
{
  KColorScheme window = KColorScheme(QPalette::Active, KColorScheme::Window);
  KColorScheme view = KColorScheme(QPalette::Active, KColorScheme::View);
  KColorScheme selection = KColorScheme(QPalette::Active, KColorScheme::Selection);

  QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);

  echo("<style type=\"text/css\">");
  indent++;
  echo("li.link:hover, div.toolbar img:hover { background: " +
       htmlColor(KColorUtils::tint(view.background().color(), view.decoration(KColorScheme::HoverColor).color(), 0.4)) + "; }");
  echo("div.column > ul, div.toolbar, p.message { background-color: " + htmlColor(view.background()) + "; " +
                  "border: 1px solid " + htmlColor(view.shade(KColorScheme::LightShade)) + "; }");
  echo("div.column > ul:hover, p.message:hover { border: 1px solid " + htmlColor(view.decoration(KColorScheme::HoverColor)) + "; }");
  echo("div.toolbar {border-top: none; border-right: none;}");
  echo("div.column { width : " + QString::number(100/columns) + "%; }");
  echo("body { font-size: " + QString::number(font.pointSize()) + "pt; " +
              "background: " + htmlColor(window.background()) + "; " +
              "color: " + htmlColor(view.foreground()) + "; }");
  indent--;
  echo("</style>");
}
Beispiel #15
0
void TodoApplet::doLayout()
{
    if (!m_view) {
        m_view = new TodoView();
        m_view->setModel(m_proxyModel);
        connect(m_view, SIGNAL(doubleClicked(const QModelIndex &)),
                        SLOT(slotOpenTodo(const QModelIndex &)));
        KColorScheme colorTheme = KColorScheme(QPalette::Active, KColorScheme::View,
                                               Plasma::Theme::defaultTheme()->colorScheme());

        // applet's title
        QLabel *title = new QLabel();
        title->setText(i18n("<font color=\"%1\">Todo list</font>",
                       colorTheme.foreground(KColorScheme::NormalText).color().name()));
        QLabel *icon = new QLabel();
        icon->setPixmap(KIcon("view-pim-tasks").pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium));

        m_widget->setObjectName("main_widget");
        m_widget->setStyleSheet("#main_widget {background: transparent}");

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

        titleLayout->addWidget(icon);
        titleLayout->addWidget(title, 1);

        // Add new todo button
        QToolButton *addButton = new QToolButton();
        addButton->setIcon(KIcon("list-add"));
        connect(addButton, SIGNAL(clicked()), SLOT(slotAddTodo()));

        // types and add button
        QHBoxLayout *footerLayout = new QHBoxLayout();
        footerLayout->addWidget(addButton);
        footerLayout->addWidget(m_types);

        // main widget
        QVBoxLayout *layout = new QVBoxLayout();
        layout->addLayout(titleLayout);
        layout->addWidget(m_view);
        layout->addWidget(m_error);
        layout->addLayout(footerLayout);

        m_widget->setLayout(layout);
    }
}
Beispiel #16
0
void KFontFamilyDelegate::paint(QPainter *painter,
                                const QStyleOptionViewItem &option,
                                const QModelIndex &index) const
{
    QBrush sampleBrush;
    if (option.state & QStyle::State_Selected) {
        painter->save();
        painter->setBrush(option.palette.highlight());
        painter->setPen(Qt::NoPen);
        painter->drawRect(option.rect);
        painter->setPen(QPen(option.palette.highlightedText(), 0));
        sampleBrush = option.palette.highlightedText();
    } else {
        sampleBrush = KColorScheme(QPalette::Normal).foreground(KColorScheme::InactiveText);
    }

    QFont baseFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
    QString trFontFamily = index.data(Qt::DisplayRole).toString();
    QString fontFamily = fontFamilyTrMap[trFontFamily];

    // Writing systems provided by the font.
    QList<QFontDatabase::WritingSystem> availableSystems = QFontDatabase().writingSystems(fontFamily);

    // Intersect font's writing systems with that specified for
    // the language's sample text, to see if the sample can be shown.
    // If the font reports no writing systems, assume it can show the sample.
    bool canShowLanguageSample = true;
    if (availableSystems.count() > 0) {
        canShowLanguageSample = false;
        QString scriptsSpec = i18nc("Numeric IDs of scripts for font previews",
                                    // i18n: Integer which indicates the script you used in the sample text
                                    // for font previews in your language. For the possible values, see
                                    // http://doc.trolltech.com/qfontdatabase.html#WritingSystem-enum
                                    // If the sample text contains several scripts, their IDs can be given
                                    // as a comma-separated list (e.g. for Japanese it is "1,27").
                                    "1");
        QStringList scriptStrIds = scriptsSpec.split(',');
        foreach (const QString &scriptStrId, scriptStrIds) {
            bool convOk;
            int ws = scriptStrId.toInt(&convOk);
            if (convOk && ws > 0 && ws < QFontDatabase::WritingSystemsCount
                    && availableSystems.contains(static_cast<QFontDatabase::WritingSystem>(ws))) {
                canShowLanguageSample = true;
                break;
            }
        }
void DolphinFileItemDelegate::paint(QPainter* painter,
                                    const QStyleOptionViewItem& option,
                                    const QModelIndex& index) const
{
    const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(index.model());
    const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(proxyModel->sourceModel());
    const bool isNameColumn = (index.column() == KDirModel::Name);

    QStyleOptionViewItemV4 opt(option);
    if (m_hasMinimizedNameColumn && isNameColumn) {
        adjustOptionWidth(opt, proxyModel, dolphinModel, index);
    }

    if (!isNameColumn) {
        // Use the inactive text color for all columns except the name column. This indicates for the user that
        // hovering other columns does not change the actions context.
        QPalette palette = opt.palette;
        if (m_cachedInactiveTextColorDirty) {
            m_cachedInactiveTextColor = KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText).color();
            m_cachedInactiveTextColorDirty = false;
        }
        palette.setColor(QPalette::Text, m_cachedInactiveTextColor);
        opt.palette = palette;
    }

    if (dolphinModel->hasVersionData() && isNameColumn) {
        // The currently shown items are under revision control. Show the current revision
        // state by adding an emblem and changing the text tintColor.
        const QModelIndex dirIndex = proxyModel->mapToSource(index);
        const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Version, dirIndex.parent());
        const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole);
        const KVersionControlPlugin::VersionState state = static_cast<KVersionControlPlugin::VersionState>(data.toInt());

        adjustOptionTextColor(opt, state);

        KFileItemDelegate::paint(painter, opt, index);

        if (state != KVersionControlPlugin::UnversionedVersion) {
            const QRect rect = iconRect(option, index);
            const QPixmap emblem = emblemForState(state, rect.size());
            painter->drawPixmap(rect.x(), rect.y() + rect.height() - emblem.height(), emblem);
        }
    } else {
        KFileItemDelegate::paint(painter, opt, index);
    }
}
Beispiel #18
0
bool KUrlLabel::event( QEvent *event )
{
  if ( event->type() == QEvent::PaletteChange ) {
    /**
     * Use parentWidget() unless you are a toplevel widget, then try qAapp
     */
    QPalette palette = parentWidget() ? parentWidget()->palette() : qApp->palette();

    palette.setBrush( QPalette::Base, palette.brush( QPalette::Normal, QPalette::Background ) );
    palette.setColor( QPalette::Foreground, this->palette().color( QPalette::Active, QPalette::Foreground ) );
    setPalette( palette );

    d->linkColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::LinkText).color();
    d->updateColor();

    return true;
  } else
    return QLabel::event( event );
}
Beispiel #19
0
void TodoApplet::dataUpdated(const QString &name, const Plasma::DataEngine::Data &data)
{
    if (QString::compare(name, CATEGORY_SOURCE) == 0) {
        updateCategories(data["categories"].toStringList());
    }
    else if (QString::compare(name, COLOR_SOURCE) == 0) {
        updateColors(data["colors"].toMap());
    }
    else if (QString::compare(name, TODO_SOURCE) == 0) {
        if (!data["error"].isNull()) {
            KColorScheme colorTheme = KColorScheme(QPalette::Active, KColorScheme::View,
                                               Plasma::Theme::defaultTheme()->colorScheme());
            setError(i18n("<b><font color=\"%1\">%2</font></b>",
                       colorTheme.foreground(KColorScheme::NegativeText).color().name(),
                       data["error"].toString()));
        }
        else {
            updateTodoList(data["todos"].toList());
        }
    }
}
Beispiel #20
0
void Token::paintEvent(QPaintEvent *pe)
{
    Q_UNUSED( pe )

    QPainter p( this );
    p.setBrush( Qt::NoBrush );
    p.setRenderHint( QPainter::Antialiasing );
    QColor c;
    if ( hasFocus() )
    {
        c = KColorScheme( QPalette::Active ).decoration( KColorScheme::HoverColor ).color();
    }
    else
    {
        c = palette().color( foregroundRole() );
        c.setAlpha( c.alpha() * 0.5 );
    }
    p.setPen( QPen( c, 2 ) );
    p.drawRoundedRect( rect().adjusted(1,1,-1,-1), 4, 4 );
    p.end();
}
Beispiel #21
0
void
RadialMap::Map::colorise()
{
    QColor cp, cb;
    double darkness = 1;
    double contrast = (double)Config::contrast / (double)100;
    int h, s1, s2, v1, v2;

    QColor kdeColour[2] = { KColorScheme(QPalette::Inactive, KColorScheme::Window).background().color(),
                            KColorScheme(QPalette::Active, KColorScheme::Window).background(KColorScheme::ActiveBackground).color() };

    double deltaRed   = (double)(kdeColour[0].red()   - kdeColour[1].red())   / 2880; //2880 for semicircle
    double deltaGreen = (double)(kdeColour[0].green() - kdeColour[1].green()) / 2880;
    double deltaBlue  = (double)(kdeColour[0].blue()  - kdeColour[1].blue())  / 2880;

    for (uint i = 0; i <= m_visibleDepth; ++i, darkness += 0.04) {
        for (Iterator<Segment> it = m_signature[i].iterator(); it != m_signature[i].end(); ++it) {
            switch (Config::scheme) {
            case 2000: //HACK for summary view

                if ((*it)->file()->name() == "Used") {
                    cb = QApplication::palette().highlight().color();
                    cb.getHsv(&h, &s1, &v1);

                    if (s1 > 80)
                        s1 = 80;

                    v2 = v1 - int(contrast * v1);
                    s2 = s1 + int(contrast * (255 - s1));

                    cb.setHsv(h, s1, v1);
                    cp.setHsv(h, s2, v2);
                } else {
                    cp = Qt::gray;
                    cb = Qt::white;
                }

                (*it)->setPalette(cp, cb);

                continue;
            case Filelight::KDE: {
                //gradient will work by figuring out rgb delta values for 360 degrees
                //then each component is angle*delta

                int a = (*it)->start();

                if (a > 2880) a = 2880 - (a - 2880);

                h  = (int)(deltaRed   * a) + kdeColour[1].red();
                s1 = (int)(deltaGreen * a) + kdeColour[1].green();
                v1 = (int)(deltaBlue  * a) + kdeColour[1].blue();

                cb.setRgb(h, s1, v1);
                cb.getHsv(&h, &s1, &v1);

                break;
            }

            case Filelight::HighContrast:

                cp.setHsv(0, 0, 0);   //values of h, s and v are irrelevant
                cb.setHsv(180, 0, int(255.0 * contrast));
                (*it)->setPalette(cp, cb);
                continue;

            default:
                h  = int((*it)->start() / 16);
                s1 = 160;
                v1 = (int)(255.0 / darkness); //****doing this more often than once seems daft!
            }

            v2 = v1 - int(contrast * v1);
            s2 = s1 + int(contrast * (255 - s1));

            if (s1 < 80) s1 = 80;  //can fall too low and makes contrast between the files hard to discern

            if ((*it)->isFake()) { //multi-file
                cb.setHsv(h, s2, (v2 < 90) ? 90 : v2);   //too dark if < 100
                cp.setHsv(h, 17, v1);
            } else if (!(*it)->file()->isDir()) { //file
                cb.setHsv(h, 17, v1);
                cp.setHsv(h, 17, v2);
            } else { //directory
                cb.setHsv(h, s1, v1);   //v was 225
                cp.setHsv(h, s2, v2);   //v was 225 - delta
            }

            (*it)->setPalette(cp, cb);

            //**** may be better to store KDE colours as H and S and vary V as others
            //**** perhaps make saturation difference for s2 dependent on contrast too
            //**** fake segments don't work with highContrast
            //**** may work better with cp = cb rather than Qt::white
            //**** you have to ensure the grey of files is sufficient, currently it works only with rainbow (perhaps use contrast there too)
            //**** change v1,v2 to vp, vb etc.
            //**** using percentages is not strictly correct as the eye doesn't work like that
            //**** darkness factor is not done for kde_colour scheme, and also value for files is incorrect really for files in this scheme as it is not set like rainbow one is
        }
    }
}
Beispiel #22
0
KDMConvenienceWidget::KDMConvenienceWidget(QWidget *parent)
    : QWidget(parent)
{
    QString wtstr;

    QLabel *paranoia = new QLabel(
        i18n("<big><b><center>Attention<br/>"
             "Read help</center></b></big>"), this);
    QPalette p;
    p.setBrush(QPalette::WindowText,
        KColorScheme(QPalette::Active, KColorScheme::Window)
            .foreground(KColorScheme::NegativeText));
    paranoia->setPalette(p);

    QSizePolicy vpref(QSizePolicy::Minimum, QSizePolicy::Fixed);

    alGroup = new QGroupBox(i18n("Enable Au&to-Login"), this);
    alGroup->setCheckable(true);
    alGroup->setSizePolicy(vpref);
    QVBoxLayout *laygroup2 = new QVBoxLayout(alGroup);
    laygroup2->setSpacing(KDialog::spacingHint());

    alGroup->setWhatsThis(i18n("Turn on the auto-login feature."
                               " This applies only to KDM's graphical login."
                               " Think twice before enabling this!"));
    connect(alGroup, SIGNAL(toggled(bool)), SIGNAL(changed()));

    userlb = new KComboBox(alGroup);

    QLabel *u_label = new QLabel(i18n("Use&r:"), alGroup);
    u_label->setBuddy(userlb);
    QHBoxLayout *hlpl1 = new QHBoxLayout();
    laygroup2->addItem(hlpl1);
    hlpl1->setSpacing(KDialog::spacingHint());
    hlpl1->addWidget(u_label);
    hlpl1->addWidget(userlb);
    hlpl1->addStretch(1);
    connect(userlb, SIGNAL(highlighted(int)), SIGNAL(changed()));
    wtstr = i18n("Select the user to be logged in automatically.");
    u_label->setWhatsThis(wtstr);
    userlb->setWhatsThis(wtstr);
    autoLockCheck = new QCheckBox(i18n("Loc&k session"), alGroup);
    laygroup2->addWidget(autoLockCheck);
    connect(autoLockCheck, SIGNAL(toggled(bool)), SIGNAL(changed()));
    autoLockCheck->setWhatsThis(i18n(
        "The automatically started session "
        "will be locked immediately (provided it is a KDE session). This can "
        "be used to obtain a super-fast login restricted to one user."));

    puGroup = new QGroupBox(i18nc("@title:group", "Preselect User"), this);

    puGroup->setSizePolicy(vpref);

    npRadio = new QRadioButton(i18nc("@option:radio preselected user", "&None"), puGroup);
    ppRadio = new QRadioButton(i18nc("@option:radio preselected user", "Prev&ious"), puGroup);
    ppRadio->setWhatsThis(i18n(
        "Preselect the user that logged in previously. "
        "Use this if this computer is usually used several consecutive times by one user."));
    spRadio = new QRadioButton(i18nc("@option:radio preselected user", "Specifi&ed:"), puGroup);
    spRadio->setWhatsThis(i18n(
        "Preselect the user specified in the combo box to the right. "
        "Use this if this computer is predominantly used by a certain user."));
    QButtonGroup *buttonGroup = new QButtonGroup(puGroup);
    connect(buttonGroup, SIGNAL(buttonClicked(int)), SLOT(slotPresChanged()));
    connect(buttonGroup, SIGNAL(buttonClicked(int)), SIGNAL(changed()));
    buttonGroup->addButton(npRadio);
    buttonGroup->addButton(ppRadio);
    buttonGroup->addButton(spRadio);
    QVBoxLayout *laygroup5 = new QVBoxLayout(puGroup);
    laygroup5->setSpacing(KDialog::spacingHint());
    laygroup5->addWidget(npRadio);
    laygroup5->addWidget(ppRadio);

    puserlb = new KComboBox(true, puGroup);

    connect(puserlb, SIGNAL(editTextChanged(QString)), SIGNAL(changed()));
    wtstr = i18n(
        "Select the user to be preselected for login. "
        "This box is editable, so you can specify an arbitrary non-existent "
        "user to mislead possible attackers.");
    puserlb->setWhatsThis(wtstr);
    QBoxLayout *hlpl = new QHBoxLayout();
    laygroup5->addItem(hlpl);
    hlpl->setSpacing(KDialog::spacingHint());
    hlpl->setMargin(0);
    hlpl->addWidget(spRadio);
    hlpl->addWidget(puserlb);
    hlpl->addStretch(1);
    // This is needed before the abuse below to ensure the combo is enabled in time
    connect(spRadio, SIGNAL(clicked(bool)), SLOT(slotPresChanged()));
    // Abuse the radio button text as a label for the combo
    connect(spRadio, SIGNAL(clicked(bool)), puserlb, SLOT(setFocus()));
    cbjumppw = new QCheckBox(i18nc("@option:check action", "Focus pass&word"), puGroup);
    laygroup5->addWidget(cbjumppw);
    cbjumppw->setWhatsThis(i18n(
        "When this option is on, KDM will place the cursor "
        "in the password field instead of the user field after preselecting a user. "
        "Use this to save one key press per login, if the preselection usually "
        "does not need to be changed."));
    connect(cbjumppw, SIGNAL(toggled(bool)), SIGNAL(changed()));

    npGroup = new QGroupBox(i18n("Enable Password-&Less Logins"), this);
    QVBoxLayout *laygroup3 = new QVBoxLayout(npGroup);
    laygroup3->setSpacing(KDialog::spacingHint());

    npGroup->setCheckable(true);

    npGroup->setWhatsThis(i18n(
        "When this option is checked, the checked users from "
        "the list below will be allowed to log in without entering their "
        "password. This applies only to KDM's graphical login. "
        "Think twice before enabling this!"));

    connect(npGroup, SIGNAL(toggled(bool)), SIGNAL(changed()));

    QLabel *pl_label = new QLabel(i18n("No password re&quired for:"), npGroup);
    laygroup3->addWidget(pl_label);
    npuserlv = new QListWidget(npGroup);
    laygroup3->addWidget(npuserlv);
    pl_label->setBuddy(npuserlv);
    npuserlv->setWhatsThis(i18n(
        "Check all users you want to allow a password-less login for. "
        "Entries denoted with '@' are user groups. Checking a group is like "
        "checking all users in that group."));

    btGroup = new QGroupBox(i18nc("@title:group", "Miscellaneous"), this);
    QVBoxLayout *laygroup4 = new QVBoxLayout(btGroup);
    laygroup4->setSpacing(KDialog::spacingHint());

    cbarlen = new QCheckBox(i18n("Automatically log in again after &X server crash"), btGroup);
    cbarlen->setWhatsThis(i18n(
        "When this option is on, a user will be "
        "logged in again automatically when their session is interrupted by an "
        "X server crash; note that this can open a security hole: if you use "
        "a screen locker than KDE's integrated one, this will make "
        "circumventing a password-secured screen lock possible."));
    //TODO a screen locker _other_ than
    laygroup4->addWidget(cbarlen);
    connect(cbarlen, SIGNAL(toggled(bool)), SIGNAL(changed()));

    QGridLayout *main = new QGridLayout(this);
    main->setSpacing(10);
    main->addWidget(paranoia, 0, 0);
    main->addWidget(alGroup, 1, 0);
    main->addWidget(puGroup, 2, 0);
    main->addWidget(npGroup, 0, 1, 4, 1);
    main->addWidget(btGroup, 4, 0, 1, 2);
    main->setColumnStretch(0, 1);
    main->setColumnStretch(1, 2);
    main->setRowStretch(3, 1);

    connect(userlb, SIGNAL(activated(QString)),
            SLOT(slotSetAutoUser(QString)));
    connect(puserlb, SIGNAL(editTextChanged(QString)),
            SLOT(slotSetPreselUser(QString)));
    connect(npuserlv, SIGNAL(itemClicked(QListWidgetItem*)),
            SLOT(slotUpdateNoPassUser(QListWidgetItem*)));

}
Beispiel #23
0
void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
    if (m_active && w == m_resizeWindow) {
        if (m_features & TextureScale) {
            data.xTranslate += m_currentGeometry.x() - m_originalGeometry.x();
            data.xScale *= m_currentGeometry.width();
            data.xScale /= m_originalGeometry.width();
            data.yTranslate += m_currentGeometry.y() - m_originalGeometry.y();
            data.yScale *= m_currentGeometry.height();
            data.yScale /= m_originalGeometry.height();
        }
        effects->paintWindow(w, mask, region, data);

        if (m_features & Outline) {
            QRegion intersection = m_originalGeometry.intersected(m_currentGeometry);
            QRegion paintRegion = QRegion(m_originalGeometry).united(m_currentGeometry).subtracted(intersection);
            float alpha = 0.8f;
            QColor color = KColorScheme(QPalette::Normal, KColorScheme::Selection).background().color();

#ifdef KWIN_HAVE_OPENGL
            if (effects->compositingType() == OpenGLCompositing) {
                GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
                vbo->reset();
                vbo->setUseColor(true);
                if (ShaderManager::instance()->isValid()) {
                    ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
                }
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                color.setAlphaF(alpha);
                vbo->setColor(color);
                QVector<float> verts;
                verts.reserve(paintRegion.rects().count() * 12);
                foreach (const QRect & r, paintRegion.rects()) {
                    verts << r.x() + r.width() << r.y();
                    verts << r.x() << r.y();
                    verts << r.x() << r.y() + r.height();
                    verts << r.x() << r.y() + r.height();
                    verts << r.x() + r.width() << r.y() + r.height();
                    verts << r.x() + r.width() << r.y();
                }
                vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
                vbo->render(GL_TRIANGLES);
                if (ShaderManager::instance()->isValid()) {
                    ShaderManager::instance()->popShader();
                }
                glDisable(GL_BLEND);
            }
#endif

#ifdef KWIN_HAVE_XRENDER_COMPOSITING
            if (effects->compositingType() == XRenderCompositing) {
                XRenderColor col;
                col.alpha = int(alpha * 0xffff);
                col.red = int(alpha * 0xffff * color.red() / 255);
                col.green = int(alpha * 0xffff * color.green() / 255);
                col.blue = int(alpha * 0xffff * color.blue() / 255);
                foreach (const QRect & r, paintRegion.rects())
                XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
                                     &col, r.x(), r.y(), r.width(), r.height());
            }
Beispiel #24
0
void DiffView::paintCell(QPainter *p, int row, int col)
{
    QFontMetrics fm(font());

    DiffViewItem *item = items.at(row);

    int width = cellWidth(col);
    int height = cellHeight();

    QColor backgroundColor;
    bool inverted;
    Qt::Alignment align;
    int innerborder;
    QString str;

    QFont oldFont(p->font());
    if (item->type==Separator)
    {
        backgroundColor = KColorScheme(QPalette::Active, KColorScheme::Selection).background().color();
        p->setPen(KColorScheme(QPalette::Active, KColorScheme::Selection).foreground().color());
        inverted = false;
        align = Qt::AlignLeft;
        innerborder = 0;
        if (col == (linenos?1:0) + (marker?1:0))
            str = item->line;
        QFont f(oldFont);
        f.setBold(true);
        p->setFont(f);
    }
    else if (col == 0 && linenos)
    {
        backgroundColor = KColorScheme(QPalette::Active, KColorScheme::Selection).background().color();
        p->setPen(KColorScheme(QPalette::Active, KColorScheme::Selection).foreground().color());
        inverted = false;
        align = Qt::AlignLeft;
        innerborder = 0;
        if (item->no == -1)
            str = "+++++";
        else
            str.setNum(item->no);
    }
    else if (marker && (col == 0 || col == 1))
    {
        backgroundColor = KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::AlternateBackground).color();
        p->setPen(KColorScheme(QPalette::Active, KColorScheme::View).foreground().color());
        inverted = false;
        align = Qt::AlignRight;
        innerborder = BORDER;
        str = (item->type==Change)? i18n("Change")
            : (item->type==Insert)? i18n("Insert")
            : (item->type==Delete)? i18n("Delete") : QString();
    }
    else
    {
        backgroundColor =
            (item->type==Change)? diffChangeColor
            : (item->type==Insert)? diffInsertColor
            : (item->type==Delete)? diffDeleteColor
            : (item->type==Neutral)? KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::AlternateBackground).color() : KColorScheme(QPalette::Active, KColorScheme::View).background().color();
        p->setPen(KColorScheme(QPalette::Active, KColorScheme::View).foreground().color());
        inverted = item->inverted;
        align = Qt::AlignLeft;
        innerborder = 0;
        str = item->line;
    }

    if (inverted)
    {
        p->setPen(backgroundColor);
        backgroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
        QFont f(oldFont);
        f.setBold(true);
        p->setFont(f);
    }

    p->fillRect(0, 0, width, height, backgroundColor);
    QTextOption textOption(align);
    textOption.setTabStop(m_tabWidth * fm.width(' '));
    p->drawText(QRectF(innerborder, 0, width-2*innerborder, height), str, textOption);
    p->setFont(oldFont);
}
Beispiel #25
0
void DiffZoomWidget::paintEvent(QPaintEvent *)
{
    const QScrollBar* scrollBar = diffview->scrollBar();
    if (!scrollBar)
        return;

    const QColor diffChangeColor(CervisiaSettings::diffChangeColor());
    const QColor diffInsertColor(CervisiaSettings::diffInsertColor());
    const QColor diffDeleteColor(CervisiaSettings::diffDeleteColor());

    // only y and height are important
    QStyleOptionSlider option;
    option.init(scrollBar);
    const QRect scrollBarGroove(scrollBar->isVisible()
                                ? style()->subControlRect(QStyle::CC_ScrollBar,
                                                          &option,
                                                          QStyle::SC_ScrollBarGroove,
                                                          scrollBar)
                                : rect());

    // draw rectangles at the positions of the differences

    const QByteArray& lineTypes(diffview->compressedContent());

    QPainter p(this);
    p.fillRect(0, scrollBarGroove.y(), width(), scrollBarGroove.height(),
               KColorScheme(QPalette::Active, KColorScheme::View).background().color());
    if (const unsigned int numberOfLines = lineTypes.size())
    {
        const double scale(((double) scrollBarGroove.height()) / numberOfLines);
        for (unsigned int index(0); index < numberOfLines;)
        {
            const char lineType(lineTypes[index]);

            // don't use qRound() to avoid painting outside of the pixmap
            // (yPos1 must be lesser than scrollBarGroove.height())
            const int yPos1(static_cast<int>(index * scale));

            // search next line with different lineType
            for (++index; index < numberOfLines && lineType == lineTypes[index]; ++index)
                ;

            QColor color;
            switch (lineType)
            {
            case 'C':
                color = diffChangeColor;
                break;
            case 'I':
                color = diffInsertColor;
                break;
            case 'D':
                color = diffDeleteColor;
                break;
            case ' ':
            case 'N':
                color = KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::AlternateBackground).color();
                break;
            }

            if (color.isValid())
            {
                const int yPos2(qRound(index * scale));
                const int areaHeight((yPos2 != yPos1) ? yPos2 - yPos1 : 1);

                p.fillRect(0, yPos1 + scrollBarGroove.y(), width(), areaHeight, QBrush(color));
            }
        }
    }
}
Beispiel #26
0
void K3b::FillStatusDisplayWidget::paintEvent( QPaintEvent* )
{
    QPainter p( this );

    const QPalette::ColorGroup colorGroup = isEnabled() ? QPalette::Normal : QPalette::Disabled;

    const Msf docSize = d->doc->length();
    const Msf cdSize = d->cdSize;
    const Msf maxValue = (cdSize > docSize ? cdSize : docSize) + ( 10*60*75 );
    const Msf tolerance = 60*75;

    QBrush fillBrush;
    if( docSize <= cdSize - tolerance ) {
        fillBrush = KColorScheme( colorGroup, KColorScheme::Selection ).background( KColorScheme::PositiveBackground );
    }
    else if( docSize > cdSize + tolerance ) {
        fillBrush = KColorScheme( colorGroup, KColorScheme::Selection ).background( KColorScheme::NegativeBackground );
    }
    else {
        fillBrush = KColorScheme( colorGroup, KColorScheme::Selection ).background( KColorScheme::NeutralBackground );
    }

    const QPen normalPen = KColorScheme( colorGroup, KColorScheme::Window ).foreground( KColorScheme::NormalText ).color();
    const QPen fillPen = KColorScheme( colorGroup, KColorScheme::Selection ).foreground( KColorScheme::NormalText ).color();

    QStyleOptionProgressBarV2 sopb;
    sopb.direction = layoutDirection();
    sopb.fontMetrics = fontMetrics();
    sopb.palette = palette();
    sopb.palette.setBrush( QPalette::Highlight, fillBrush );
    sopb.rect = rect();
    sopb.state = isEnabled() ? QStyle::State_Enabled : QStyle::State_None;
    sopb.minimum = 0;
    sopb.maximum = maxValue.totalFrames();
    sopb.progress = docSize.totalFrames();
    style()->drawControl( QStyle::CE_ProgressBar, &sopb, &p );

    const QRect barRect = style()->subElementRect( QStyle::SE_ProgressBarContents, &sopb );

    // so split width() in maxValue pieces
    double one = (double)barRect.width() / (double)maxValue.totalFrames();

    QRect crect( barRect );
    crect.setWidth( (int)(one*(double)docSize.totalFrames()) );

    // ====================================================================================
    // Now the colored bar is painted
    // Continue with the texts
    // ====================================================================================

    // first we determine the text to display
    // ====================================================================================
    QString docSizeText;
    if( d->showTime )
        docSizeText = i18n("%1 min", d->doc->length().toString(false));
    else
        docSizeText = KIO::convertSize( d->doc->size() );

    QString overSizeText;
    if( d->cdSize.mode1Bytes() >= d->doc->size() )
        overSizeText = i18n("Available: %1 of %2",
                            d->showTime
                            ? i18n("%1 min", (cdSize - d->doc->length()).toString(false) )
                            : KIO::convertSize( (cdSize - d->doc->length()).mode1Bytes() ),
                            d->showTime
                            ? i18n("%1 min", cdSize.toString(false))
                            : KIO::convertSize( cdSize.mode1Bytes() ) );
    else
        overSizeText = i18n("Capacity exceeded by %1",
                            d->showTime
                            ? i18n("%1 min", (d->doc->length() - cdSize ).toString(false))
                            : KIO::convertSize( (long long)d->doc->size() - cdSize.mode1Bytes() ) );
    // ====================================================================================

    // calculate the medium size marker
    // ====================================================================================
    int mediumSizeMarkerPos = barRect.left() + (int)(one*cdSize.lba());
    QPoint mediumSizeMarkerFrom( mediumSizeMarkerPos, barRect.bottom() );
    QPoint mediumSizeMarkerTo( mediumSizeMarkerPos, barRect.top() + barRect.height()/2 );
    // ====================================================================================

    // we want to draw the docSizeText centered in the filled area
    // if there is not enough space we just align it left
    // ====================================================================================
    int docSizeTextPos = 0;
    int docSizeTextLength = fontMetrics().width(docSizeText);
    if( docSizeTextLength + 5 > crect.width() ) {
        docSizeTextPos = crect.left() + 5; // a little margin
    }
    else {
        docSizeTextPos = ( crect.width() - docSizeTextLength ) / 2;

        // make sure the text does not cross the medium size marker
        if( docSizeTextPos <= mediumSizeMarkerPos && mediumSizeMarkerPos <= docSizeTextPos + docSizeTextLength )
            docSizeTextPos = qMax( crect.left() + 5, mediumSizeMarkerPos - docSizeTextLength - 5 );
    }
    // ====================================================================================

    // calculate the over size text
    // ====================================================================================
    QFont overSizeFont(font());
    overSizeFont.setPointSize( qMax( 8, overSizeFont.pointSize()-4 ) );
    overSizeFont.setBold(false);

    QRect overSizeTextRect( barRect );
    int overSizeTextLength = QFontMetrics(overSizeFont).width(overSizeText);
    if( overSizeTextLength + 5 > overSizeTextRect.width() - (int)(one*cdSize.totalFrames()) ) {
        // we don't have enough space on the right, so we paint to the left of the line
        overSizeTextRect.setLeft( (int)(one*cdSize.totalFrames()) - overSizeTextLength - 5 );
    }
    else {
        overSizeTextRect.setLeft( mediumSizeMarkerPos + 5 );
    }

    // make sure the two text do not overlap (this does not cover all cases though)
    if( overSizeTextRect.left() < docSizeTextPos + docSizeTextLength )
        docSizeTextPos = qMax( crect.left() + 5, qMin( overSizeTextRect.left() - docSizeTextLength - 5, mediumSizeMarkerPos - docSizeTextLength - 5 ) );

    QRect docTextRect( barRect );
    docTextRect.setLeft( docSizeTextPos );

    // Draw the fill part
    p.setPen( fillPen );
    p.setClipRect( QStyle::visualRect( layoutDirection(), barRect, crect ) );
    p.drawLine( QStyle::visualPos( layoutDirection(), barRect, mediumSizeMarkerFrom ),
                QStyle::visualPos( layoutDirection(), barRect, mediumSizeMarkerTo ) );
    p.drawText( QStyle::visualRect( layoutDirection(), barRect, docTextRect ),
                QStyle::visualAlignment( layoutDirection(), Qt::AlignLeft | Qt::AlignVCenter ), docSizeText );
    p.setFont(overSizeFont);
    p.drawText( QStyle::visualRect( layoutDirection(), barRect, overSizeTextRect ),
                QStyle::visualAlignment( layoutDirection(), Qt::AlignLeft | Qt::AlignVCenter ), overSizeText );

    // Draw the remain part
    p.setPen( normalPen );
    p.setClipRect( QStyle::visualRect( layoutDirection(), barRect,
                                       QRect( crect.right(), barRect.top(), barRect.width()-crect.width(), barRect.height() ) ) );
    p.drawLine( QStyle::visualPos( layoutDirection(), barRect, mediumSizeMarkerFrom ),
                QStyle::visualPos( layoutDirection(), barRect, mediumSizeMarkerTo ) );
    p.setFont( font() );
    p.drawText( QStyle::visualRect( layoutDirection(), barRect, docTextRect ),
                QStyle::visualAlignment( layoutDirection(), Qt::AlignLeft | Qt::AlignVCenter ), docSizeText );
    p.setFont(overSizeFont);
    p.drawText( QStyle::visualRect( layoutDirection(), barRect, overSizeTextRect ),
                QStyle::visualAlignment( layoutDirection(), Qt::AlignLeft | Qt::AlignVCenter ), overSizeText );
    // ====================================================================================
}
Beispiel #27
0
void KBounceGameWidget::generateOverlay()
{
	if ( size().isEmpty() )
		return;
	
    int itemWidth = qRound( 0.8 * size().width() );
    int itemHeight = qRound( 0.6 * size().height() );

	QSize backgroundSize( itemWidth,itemHeight );

	QPixmap px( backgroundSize );
	px.fill( Qt::transparent );

	QPainter p( &px );
	
	p.setPen( Qt::transparent );
	p.setRenderHint(QPainter::Antialiasing );
	
	if ( m_renderer.spriteExists("overlayBackground") )
	{
		QPixmap themeBackgound = m_renderer.spritePixmap("overlayBackground",backgroundSize);
		p.setCompositionMode( QPainter::CompositionMode_Source );
		p.drawPixmap( p.viewport(), themeBackgound );
		p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
		p.fillRect(px.rect(), QColor( 0, 0, 0, 160 ));
		p.setCompositionMode( QPainter::CompositionMode_SourceOver );
	}
	else
	{
		p.setBrush( QBrush( QColor( 188, 202, 222, 155 ) ) );
		p.drawRoundRect( 0, 0, itemWidth, itemHeight, 25 );
	}
	
	QString text;
	switch( m_state )
	{
	case BeforeFirstGame:
	    text = i18n( "Welcome to KBounce.\n Click to start a game" );
	    break;
	case Paused:
	    text = i18n( "Paused" );
	    break;
	case BetweenLevels:
	    text = i18n( "You have successfully cleared more than %1% of the board\n", MIN_FILL_PERCENT ) +
		i18n( "%1 points: %2 points per remaining life\n", m_lives * POINTS_FOR_LIFE, POINTS_FOR_LIFE ) +
		i18n( "%1 points: Bonus\n", m_bonus ) +
		i18n( "%1 points: Total score for this level\n", m_bonus + m_lives * POINTS_FOR_LIFE ) +
		i18n( "On to level %1. Remember you get %2 lives this time!", m_level, m_level + 1 );
	    break;
	case GameOver:
	    text = i18n( "Game over.\n Click to start a game" );
	    break;
	default:
	    text = QString();
    }

    QFont font;
    font.setPointSize( 28 );
    p.setFont( font );
    int textWidth = p.boundingRect( p.viewport(), Qt::AlignCenter | Qt::AlignVCenter, text ).width();
    int fontSize = 28;
    while ( ( textWidth > itemWidth * 0.95 ) && fontSize > 1 )
    {
        fontSize--;
        font.setPointSize( fontSize );
        p.setFont( font );
        textWidth = p.boundingRect( p.viewport(), Qt::AlignCenter | Qt::AlignVCenter, text ).width();
    }
    KColorScheme kcs = KColorScheme( QPalette::Normal, KColorScheme::Window );
    p.setPen( kcs.foreground(KColorScheme::NormalText).color()); 
    p.drawText( p.viewport(), Qt::AlignCenter | Qt::AlignVCenter, text );
    p.end();

    m_overlay->setPixmap( px );
    m_overlay->moveTo( ( size().width() - itemWidth ) / 2, ( size().height() - itemHeight ) / 2 );
}
Beispiel #28
0
QPixmap KIconEffect::apply(const QPixmap &pixmap, int effect, float value,
                           const QColor &col, bool trans) const
{
    return apply(pixmap, effect, value, col,
                 KColorScheme(QPalette::Active, KColorScheme::View).background().color(), trans);
}