Esempio n. 1
0
void KMenuBar::checkSize(int &w, int &h)
{
    if(!d->topLevel || d->fallback_mode)
        return;
    QSize s = sizeHint();
    w = s.width();
    h = s.height();
    // This is not done as setMinimumSize(), because that would set the minimum
    // size in WM_NORMAL_HINTS, and KWin would not allow changing to smaller size
    // anymore
    w = KMAX(w, d->min_size.width());
    h = KMAX(h, d->min_size.height());
}
Esempio n. 2
0
KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
{
    const int range = 16;
    int bleft, bright, btop, bbottom;
    borders( bleft, bright, btop, bbottom );
    btop = KMIN( btop, 4 ); // otherwise whole titlebar would have resize cursor

    Position m = PositionCenter;

    if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
            && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
        return PositionCenter;

    if ( p.y() <= KMAX( range, btop ) && p.x() <= KMAX( range, bleft ))
        m = PositionTopLeft;
    else if ( p.y() >= widget()->height()- KMAX( range, bbottom )
              && p.x() >= widget()->width()- KMAX( range, bright ))
        m = PositionBottomRight;
    else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) && p.x() <= KMAX( range, bleft ))
        m = PositionBottomLeft;
    else if ( p.y() <= KMAX( range, btop ) && p.x() >= widget()->width()- KMAX( range, bright ))
        m = PositionTopRight;
    else if ( p.y() <= btop )
        m = PositionTop;
    else if ( p.y() >= widget()->height()-bbottom )
        m = PositionBottom;
    else if ( p.x() <= bleft )
        m = PositionLeft;
    else if ( p.x() >= widget()->width()-bright )
        m = PositionRight;
    else
        m = PositionCenter;
    return m;
}
Esempio n. 3
0
int PanelButton::widthForHeight(int height) const
{
    int rc = preferredDimension(height);

    // we only paint the text when horizontal, so make sure we're horizontal
    // before adding the text in here
    if (orientation() == Horizontal && !m_buttonText.isEmpty())
    {
        QFont f(font());
        f.setPixelSize(KMIN(height, KMAX(int(float(height) * m_fontPercent), 16)));
        QFontMetrics fm(f);

        rc += fm.width(m_buttonText) + KMIN(25, KMAX(5, fm.width('m') / 2));
    }

    return rc;
}
Esempio n. 4
0
int KST::vectorsToFile(const KstVectorList& vl, QFile *f, bool interpolate) {
  KstApp *app = KstApp::inst();
  int maxlen = -1;

  if (interpolate) { // code duplication is faster
    maxlen = 0;
    for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
      (*v)->readLock();
      maxlen = KMAX(maxlen, (*v)->length());
    }
  } else {
    for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
      (*v)->readLock();
      if (maxlen == -1) {
        maxlen = (*v)->length();
      } else {
        maxlen = KMIN(maxlen, (*v)->length());
      }
    }
  }

  QString saving = i18n("Saving vectors...");
  register int modval = QMAX(maxlen/100, 100);
  app->slotUpdateProgress(maxlen, 0, QString::null);

  bool first = true;
  QString ltxt = ";";
  for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
    ltxt += ' ';
    ltxt += (*v)->tagName();
  }
  ltxt += '\n';

  f->writeBlock(ltxt.ascii(), ltxt.length());
  ltxt.fill('-');
  ltxt[0] = ';';
  ltxt[1] = ' ';
  ltxt[ltxt.length() - 1] = '\n';
  f->writeBlock(ltxt.ascii(), ltxt.length());
#if QT_VERSION >= 0x030200
  ltxt.reserve(vl.count()*17);
#endif
  for (int line = 0; line < maxlen; ++line) {
    ltxt.truncate(0);
    first = true;
    for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
      if (!first) {
        ltxt += ' ';
      } else {
        first = false;
      }
      double val;
      if (interpolate) {  // might be faster to put this outside the for loops
        val = (*v)->interpolate(line, maxlen);
      } else {
        val = (*v)->value()[line];
      } 
      ltxt += QString::number(val, 'g', 15);
    }
    ltxt += "\n";
    f->writeBlock(ltxt.ascii(), ltxt.length());
    if (line % modval == 0) {
      app->slotUpdateProgress(maxlen, line, saving);
    }
  }

  for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
    (*v)->readUnlock();
  }

  app->slotUpdateProgress(0, 0, QString::null);

  return 0;
}
Esempio n. 5
0
void PanelButton::drawButtonLabel(QPainter *p)
{
    QPixmap icon = labelIcon();
    bool active = isDown() || isOn();

    if (active)
    {
        icon = icon.convertToImage().smoothScale(icon.width() - 2,
                                                 icon.height() - 2);
    }

    if (!m_buttonText.isEmpty() && orientation() == Horizontal)
    {
        int h = height();
        int w = width();
        int y = (h - icon.height())/2;
        p->save();
        QFont f = font();

        double fontPercent = m_fontPercent;
        if (active)
        {
            fontPercent *= .8;
        }
        f.setPixelSize(KMIN(h, KMAX(int(float(h) * m_fontPercent), 16)));
        QFontMetrics fm(f);
        p->setFont(f);

        /* Draw shadowed text */
        bool reverse = QApplication::reverseLayout();
        QPainter::TextDirection rtl = reverse ? QPainter::RTL : QPainter::LTR;

        if (!reverse && !icon.isNull())
        {
            /* Draw icon */
            p->drawPixmap(3, y, icon);
        }

        int tX = reverse ? 3 : icon.width() + KMIN(25, KMAX(5, fm.width('m') / 2));
        int tY = fm.ascent() + ((h - fm.height()) / 2);

        QColor shadCol = KickerLib::shadowColor(m_textColor);

        // get a transparent pixmap
        QPainter pixPainter;
        QPixmap textPixmap(w, h);

        textPixmap.fill(QColor(0,0,0));
        textPixmap.setMask(textPixmap.createHeuristicMask(true));

        // draw text
        pixPainter.begin(&textPixmap);
        pixPainter.setPen(m_textColor);
        pixPainter.setFont(p->font()); // get the font from the root painter
        pixPainter.drawText(tX, tY, m_buttonText, -1, rtl);
        pixPainter.end();

        if (!s_textShadowEngine)
        {
            KShadowSettings* shadset = new KShadowSettings();
            shadset->setOffsetX(0);
            shadset->setOffsetY(0);
            shadset->setThickness(1);
            shadset->setMaxOpacity(96);
            s_textShadowEngine = new KShadowEngine(shadset);
        }

        // draw shadow
        QImage img = s_textShadowEngine->makeShadow(textPixmap, shadCol);
        p->drawImage(0, 0, img);
        p->save();
        p->setPen(m_textColor);
        p->drawText(tX, tY, m_buttonText, -1, rtl);
        p->restore();

        if (reverse && !icon.isNull())
        {
            p->drawPixmap(w - icon.width() - 3, y, icon);
        }

        p->restore();
    }
    else if (!icon.isNull())
    {
        int y = (height() - icon.height()) / 2;
        int x = (width()  - icon.width()) / 2;
        p->drawPixmap(x, y, icon);
    }

    if (m_drawArrow && (m_highlight || active))
    {
        QStyle::PrimitiveElement e = QStyle::PE_ArrowUp;
        int arrowSize = style().pixelMetric(QStyle::PM_MenuButtonIndicator);
        QRect r((width() - arrowSize)/2, 0, arrowSize, arrowSize);

        switch (m_arrowDirection)
        {
            case KPanelExtension::Top:
                e = QStyle::PE_ArrowUp;
                break;
            case KPanelExtension::Bottom:
                e = QStyle::PE_ArrowDown;
                r.moveBy(0, height() - arrowSize);
                break;
            case KPanelExtension::Right:
                e = QStyle::PE_ArrowRight;
                r = QRect(width() - arrowSize, (height() - arrowSize)/2, arrowSize, arrowSize);
                break;
            case KPanelExtension::Left:
                e = QStyle::PE_ArrowLeft;
                r = QRect(0, (height() - arrowSize)/2, arrowSize, arrowSize);
                break;
            case KPanelExtension::Floating:
                if (orientation() == Horizontal)
                {
                    e = QStyle::PE_ArrowDown;
                    r.moveBy(0, height() - arrowSize);
                }
                else if (QApplication::reverseLayout())
                {
                    e = QStyle::PE_ArrowLeft;
                    r = QRect(0, (height() - arrowSize)/2, arrowSize, arrowSize);
                }
                else
                {
                    e = QStyle::PE_ArrowRight;
                    r = QRect(width() - arrowSize, (height() - arrowSize)/2, arrowSize, arrowSize);
                }
                break;
        }

        int flags = QStyle::Style_Enabled;
        if (active)
        {
            flags |= QStyle::Style_Down;
        }
        style().drawPrimitive(e, p, r, colorGroup(), flags);
    }
}
Esempio n. 6
0
unsigned long Options::updateSettings()
{
    KConfig *config = KGlobal::config();
    unsigned long changed = 0;
    changed |= d->updateKWinSettings(config); // read decoration settings

    config->setGroup("Windows");
    moveMode = stringToMoveResizeMode(config->readEntry("MoveMode", "Opaque"));
    resizeMode = stringToMoveResizeMode(config->readEntry("ResizeMode", "Opaque"));
    show_geometry_tip = config->readBoolEntry("GeometryTip", false);
    tabboxOutline = config->readBoolEntry("TabboxOutline", true);

    QString val;

    val = config->readEntry("FocusPolicy", "ClickToFocus");
    focusPolicy = ClickToFocus; // what a default :-)
    if(val == "FocusFollowsMouse")
        focusPolicy = FocusFollowsMouse;
    else if(val == "FocusUnderMouse")
        focusPolicy = FocusUnderMouse;
    else if(val == "FocusStrictlyUnderMouse")
        focusPolicy = FocusStrictlyUnderMouse;

    val = config->readEntry("AltTabStyle", "KDE");
    altTabStyle = KDE; // what a default :-)
    if(val == "CDE")
        altTabStyle = CDE;

    rollOverDesktops = config->readBoolEntry("RollOverDesktops", TRUE);

    //    focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 2 );
    // TODO use low level for now
    focusStealingPreventionLevel = config->readNumEntry("FocusStealingPreventionLevel", 1);
    focusStealingPreventionLevel = KMAX(0, KMIN(4, focusStealingPreventionLevel));
    if(!focusPolicyIsReasonable()) // #48786, comments #7 and later
        focusStealingPreventionLevel = 0;

    KConfig *gc = new KConfig("kdeglobals", false, false);
    gc->setGroup("Windows");
    xineramaEnabled = gc->readBoolEntry("XineramaEnabled", true);
    xineramaPlacementEnabled = gc->readBoolEntry("XineramaPlacementEnabled", true);
    xineramaMovementEnabled = gc->readBoolEntry("XineramaMovementEnabled", true);
    xineramaMaximizeEnabled = gc->readBoolEntry("XineramaMaximizeEnabled", true);
    xineramaFullscreenEnabled = gc->readBoolEntry("XineramaFullscreenEnabled", true);
    delete gc;

    placement = Placement::policyFromString(config->readEntry("Placement"), true);

    animateShade = config->readBoolEntry("AnimateShade", TRUE);

    animateMinimize = config->readBoolEntry("AnimateMinimize", TRUE);
    animateMinimizeSpeed = config->readNumEntry("AnimateMinimizeSpeed", 5);

    if(focusPolicy == ClickToFocus)
    {
        autoRaise = false;
        autoRaiseInterval = 0;
        delayFocus = false;
        delayFocusInterval = 0;
    }
    else
    {
        autoRaise = config->readBoolEntry("AutoRaise", FALSE);
        autoRaiseInterval = config->readNumEntry("AutoRaiseInterval", 0);
        delayFocus = config->readBoolEntry("DelayFocus", FALSE);
        delayFocusInterval = config->readNumEntry("DelayFocusInterval", 0);
    }

    shadeHover = config->readBoolEntry("ShadeHover", FALSE);
    shadeHoverInterval = config->readNumEntry("ShadeHoverInterval", 250);

    // important: autoRaise implies ClickRaise
    clickRaise = autoRaise || config->readBoolEntry("ClickRaise", TRUE);

    borderSnapZone = config->readNumEntry("BorderSnapZone", 10);
    windowSnapZone = config->readNumEntry("WindowSnapZone", 10);
    snapOnlyWhenOverlapping = config->readBoolEntry("SnapOnlyWhenOverlapping", FALSE);
    electric_borders = config->readNumEntry("ElectricBorders", 0);
    electric_border_delay = config->readNumEntry("ElectricBorderDelay", 150);

    OpTitlebarDblClick = windowOperation(config->readEntry("TitlebarDoubleClickCommand", "Shade"), true);
    d->OpMaxButtonLeftClick = windowOperation(config->readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true);
    d->OpMaxButtonMiddleClick = windowOperation(config->readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true);
    d->OpMaxButtonRightClick = windowOperation(config->readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true);

    ignorePositionClasses = config->readListEntry("IgnorePositionClasses");
    ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses");
    // Qt3.2 and older had resource class all lowercase, but Qt3.3 has it capitalized
    // therefore Client::resourceClass() forces lowercase, force here lowercase as well
    for(QStringList::Iterator it = ignorePositionClasses.begin(); it != ignorePositionClasses.end(); ++it)
        (*it) = (*it).lower();
    for(QStringList::Iterator it = ignoreFocusStealingClasses.begin(); it != ignoreFocusStealingClasses.end(); ++it)
        (*it) = (*it).lower();

    killPingTimeout = config->readNumEntry("KillPingTimeout", 5000);
    hideUtilityWindowsForInactive = config->readBoolEntry("HideUtilityWindowsForInactive", true);
    showDesktopIsMinimizeAll = config->readBoolEntry("ShowDesktopIsMinimizeAll", false);

    // Mouse bindings
    config->setGroup("MouseBindings");
    CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1", "Raise"), true);
    CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2", "Lower"), true);
    CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3", "Operations menu"), true);
    CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1", "Activate and raise"), true);
    CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2", "Activate and lower"), true);
    CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3", "Operations menu"), true);
    CmdTitlebarWheel = mouseWheelCommand(config->readEntry("CommandTitlebarWheel", "Nothing"));
    CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1", "Activate, raise and pass click"), false);
    CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2", "Activate and pass click"), false);
    CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3", "Activate and pass click"), false);
    CmdAllModKey = (config->readEntry("CommandAllKey", "Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
    CmdAll1 = mouseCommand(config->readEntry("CommandAll1", "Move"), false);
    CmdAll2 = mouseCommand(config->readEntry("CommandAll2", "Toggle raise and lower"), false);
    CmdAll3 = mouseCommand(config->readEntry("CommandAll3", "Resize"), false);
    CmdAllWheel = mouseWheelCommand(config->readEntry("CommandAllWheel", "Nothing"));

    // translucency settings
    config->setGroup("Notification Messages");
    useTranslucency = config->readBoolEntry("UseTranslucency", false);
    config->setGroup("Translucency");
    translucentActiveWindows = config->readBoolEntry("TranslucentActiveWindows", false);
    activeWindowOpacity = uint((config->readNumEntry("ActiveWindowOpacity", 100) / 100.0) * 0xFFFFFFFF);
    translucentInactiveWindows = config->readBoolEntry("TranslucentInactiveWindows", false);
    inactiveWindowOpacity = uint((config->readNumEntry("InactiveWindowOpacity", 75) / 100.0) * 0xFFFFFFFF);
    translucentMovingWindows = config->readBoolEntry("TranslucentMovingWindows", false);
    movingWindowOpacity = uint((config->readNumEntry("MovingWindowOpacity", 50) / 100.0) * 0xFFFFFFFF);
    translucentDocks = config->readBoolEntry("TranslucentDocks", false);
    dockOpacity = uint((config->readNumEntry("DockOpacity", 80) / 100.0) * 0xFFFFFFFF);
    keepAboveAsActive = config->readBoolEntry("TreatKeepAboveAsActive", true);
    // TODO: remove this variable
    useTitleMenuSlider = true;
    activeWindowShadowSize = config->readNumEntry("ActiveWindowShadowSize", 200);
    inactiveWindowShadowSize = config->readNumEntry("InactiveWindowShadowSize", 100);
    dockShadowSize = config->readNumEntry("DockShadowSize", 80);
    removeShadowsOnMove = config->readBoolEntry("RemoveShadowsOnMove", true);
    removeShadowsOnResize = config->readBoolEntry("RemoveShadowsOnResize", true);
    onlyDecoTranslucent = config->readBoolEntry("OnlyDecoTranslucent", false);
    resetKompmgr = config->readBoolEntry("ResetKompmgr", false);
    if(resetKompmgr)
        config->writeEntry("ResetKompmgr", FALSE);


    // Read button tooltip animation effect from kdeglobals
    // Since we want to allow users to enable window decoration tooltips
    // and not kstyle tooltips and vise-versa, we don't read the
    // "EffectNoTooltip" setting from kdeglobals.
    KConfig globalConfig("kdeglobals");
    globalConfig.setGroup("KDE");
    topmenus = globalConfig.readBoolEntry("macStyle", false);

    KConfig kdesktopcfg("kdesktoprc", true);
    kdesktopcfg.setGroup("Menubar");
    desktop_topmenu = kdesktopcfg.readBoolEntry("ShowMenubar", false);
    if(desktop_topmenu)
        topmenus = true;

    QToolTip::setGloballyEnabled(d->show_tooltips);

    return changed;
}