示例#1
0
int MSLayout::idealWidth(void) const
{
  int offset=highlightThickness()+shadowThickness()+margin();
  int w=(vectorWidth()+2*innerWidth()+(columns()-1)*columnSpacing()+2*offset);
  if (label()->mapped()==MSTrue)
   {
     int lw=label()->width()+2*offset;
     if ((titleAlignment()&MSLeft)||(titleAlignment()&MSRight))
     lw+=(2*XTextWidth(fontManager()->fontStruct(label()->font()),"M",1));
     return (w>lw)?w:lw;
   }
  else return w;
}
    //________________________________________________________
    bool Configuration::operator == (const Configuration& other ) const
    {

        return
            titleAlignment() == other.titleAlignment() &&
            centerTitleOnFullWidth() == other.centerTitleOnFullWidth() &&
            buttonSize() == other.buttonSize() &&
            frameBorder() == other.frameBorder() &&
            blendColor() == other.blendColor() &&
            sizeGripMode() == other.sizeGripMode() &&
            backgroundOpacity() == other.backgroundOpacity()&&
            separatorMode() == other.separatorMode() &&
            drawTitleOutline() == other.drawTitleOutline() &&
            hideTitleBar() == other.hideTitleBar() &&
            useDropShadows() == other.useDropShadows() &&
            useOxygenShadows() == other.useOxygenShadows() &&
            closeFromMenuButton() == other.closeFromMenuButton() &&
            transparencyEnabled() == other.transparencyEnabled() &&
            useNarrowButtonSpacing() == other.useNarrowButtonSpacing() &&
            useExtendedWindowBorder() == other.useExtendedWindowBorder() &&
            opacityFromStyle() == other.opacityFromStyle() &&
            backgroundOpacity() == other.backgroundOpacity() &&
            animationsEnabled() == other.animationsEnabled() &&
            buttonAnimationsEnabled() == other.buttonAnimationsEnabled() &&
            titleAnimationsEnabled() == other.titleAnimationsEnabled() &&
            shadowAnimationsEnabled() == other.shadowAnimationsEnabled() &&
            tabAnimationsEnabled() == other.tabAnimationsEnabled() &&
            buttonAnimationsDuration() == other.buttonAnimationsDuration() &&
            titleAnimationsDuration() == other.titleAnimationsDuration() &&
            shadowAnimationsDuration() == other.shadowAnimationsDuration() &&
            tabAnimationsDuration() == other.tabAnimationsDuration();

    }
示例#3
0
void MSLayout::positionLabel(void)
{
  if (label()->columns()>0)
   {
     int xpos,ypos;
     int indent;
     if (titleAlignment()&MSLeft) 
      {
	indent=XTextWidth(fontManager()->fontStruct(label()->font()),"M",1);
	xpos=highlightThickness()+shadowThickness()+margin()+indent;
      }
     else if (titleAlignment()&MSRight) 
      {
	indent=XTextWidth(fontManager()->fontStruct(label()->font()),"M",1);
	xpos=width()-(highlightThickness()+shadowThickness()+margin())-indent-label()->width();
      }
     else xpos=width()/2-label()->width()/2;

     if (titleAlignment()&MSTop) 
      {
	topShadowOffset(label()->height());
	ypos=0;
      }
     else if (titleAlignment()&MSBottom) 
      {
	topShadowOffset(0);
	ypos=highlightThickness()+shadowThickness()+margin();
      }
     else
      { 
	topShadowOffset(label()->height()/2);
	ypos=0;
      }
     label()->moveTo(xpos,ypos);
     if (mapped()==MSFalse) label()->map();
   }
  else
   { 
     label()->unmap();
     topShadowOffset(0);
   }
}
    //__________________________________________________
    void Configuration::write( KConfigGroup& group ) const
    {

        Configuration defaultConfiguration;

        if( titleAlignment() != defaultConfiguration.titleAlignment() ) group.writeEntry( OxygenConfig::TITLE_ALIGNMENT, titleAlignmentName( false ) );
        if( centerTitleOnFullWidth() != defaultConfiguration.centerTitleOnFullWidth() ) group.writeEntry( OxygenConfig::CENTER_TITLE_ON_FULL_WIDTH, centerTitleOnFullWidth() );
        if( buttonSize() != defaultConfiguration.buttonSize() ) group.writeEntry( OxygenConfig::BUTTON_SIZE, buttonSizeName( false ) );
        if( blendColor() != defaultConfiguration.blendColor() ) group.writeEntry( OxygenConfig::BLEND_COLOR, blendColorName( false ) );
        if( frameBorder() != defaultConfiguration.frameBorder() ) group.writeEntry( OxygenConfig::FRAME_BORDER, frameBorderName( false ) );
        if( sizeGripMode() != defaultConfiguration.sizeGripMode() ) group.writeEntry( OxygenConfig::SIZE_GRIP_MODE, sizeGripModeName( false ) );

        if( backgroundOpacity() != defaultConfiguration.backgroundOpacity() ) group.writeEntry( OxygenConfig::BACKGROUND_OPACITY, backgroundOpacity() );
        if( opacityFromStyle() != defaultConfiguration.opacityFromStyle() ) group.writeEntry( OxygenConfig::OPACITY_FROM_STYLE, opacityFromStyle() );

        if( separatorMode() != defaultConfiguration.separatorMode() )
        {
            group.writeEntry( OxygenConfig::DRAW_SEPARATOR, separatorMode() != SeparatorNever );
            group.writeEntry( OxygenConfig::SEPARATOR_ACTIVE_ONLY, separatorMode() == SeparatorActive );
        }

        if( drawTitleOutline() != defaultConfiguration.drawTitleOutline() ) group.writeEntry( OxygenConfig::DRAW_TITLE_OUTLINE, drawTitleOutline() );
        if( hideTitleBar() != defaultConfiguration.hideTitleBar() ) group.writeEntry( OxygenConfig::HIDE_TITLEBAR, hideTitleBar() );
        if( useDropShadows() != defaultConfiguration.useDropShadows() ) group.writeEntry( OxygenConfig::USE_DROP_SHADOWS, useDropShadows() );
        if( useOxygenShadows() != defaultConfiguration.useOxygenShadows() ) group.writeEntry( OxygenConfig::USE_OXYGEN_SHADOWS, useOxygenShadows() );
        if( closeFromMenuButton() != defaultConfiguration.closeFromMenuButton() ) group.writeEntry( OxygenConfig::CLOSE_FROM_MENU_BUTTON, closeFromMenuButton() );
        if( useNarrowButtonSpacing() != defaultConfiguration.useNarrowButtonSpacing() ) group.writeEntry( OxygenConfig::NARROW_BUTTON_SPACING, useNarrowButtonSpacing() );
        if( useExtendedWindowBorder() != defaultConfiguration.useExtendedWindowBorder() ) group.writeEntry( OxygenConfig::EXTENDED_WINDOW_BORDERS, useExtendedWindowBorder() );

        // animations
        if( animationsEnabled() != defaultConfiguration.animationsEnabled() ) group.writeEntry( OxygenConfig::ANIMATIONS_ENABLED, animationsEnabled() );
        if( buttonAnimationsEnabled() != defaultConfiguration.buttonAnimationsEnabled() ) group.writeEntry( OxygenConfig::BUTTON_ANIMATIONS_ENABLED, buttonAnimationsEnabled() );
        if( titleAnimationsEnabled() != defaultConfiguration.titleAnimationsEnabled() ) group.writeEntry( OxygenConfig::TITLE_ANIMATIONS_ENABLED, titleAnimationsEnabled() );
        if( shadowAnimationsEnabled() != defaultConfiguration.shadowAnimationsEnabled() ) group.writeEntry( OxygenConfig::SHADOW_ANIMATIONS_ENABLED, shadowAnimationsEnabled() );
        if( tabAnimationsEnabled() != defaultConfiguration.tabAnimationsEnabled() ) group.writeEntry( OxygenConfig::TAB_ANIMATIONS_ENABLED, tabAnimationsEnabled() );

        // animations duration
        if( buttonAnimationsDuration() != defaultConfiguration.buttonAnimationsDuration() ) group.writeEntry( OxygenConfig::BUTTON_ANIMATIONS_DURATION, buttonAnimationsDuration() );
        if( titleAnimationsDuration() != defaultConfiguration.titleAnimationsDuration() ) group.writeEntry( OxygenConfig::TITLE_ANIMATIONS_DURATION, titleAnimationsDuration() );
        if( shadowAnimationsDuration() != defaultConfiguration.shadowAnimationsDuration() ) group.writeEntry( OxygenConfig::SHADOW_ANIMATIONS_DURATION, shadowAnimationsDuration() );
        if( tabAnimationsDuration() != defaultConfiguration.tabAnimationsDuration() ) group.writeEntry( OxygenConfig::TAB_ANIMATIONS_DURATION, tabAnimationsDuration() );

    }
示例#5
0
void tGraph::draw(QPainter & paint) {
    //QPainter paint(this);
    paint.save();

    int gx1 = hPadding() + _rect.x();
    int gy1 = vPadding() + _rect.y();
    int gx2 = _rect.x() + width() - hPadding();
    int gy2 = _rect.y() + height() - vPadding();

    //paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);

    QFontMetrics fm(font());
    //QRect brect;

    // get the dimensions of the title label and then draw it
    if(title().length() > 0) {
        fm = QFontMetrics(titleFont());
        //brect = fm.boundingRect(title());
        paint.setFont(titleFont());
        paint.drawText(gx1, gy1, gx2 - gx1, fm.height(), titleAlignment(), title());
        gy1 += fm.height();
    }

    // we need to do some drawing that depends on some other elements having
    // already been placed... since those require that these have already been
    // placed we will just save the old value of gy2 and then calculate the
    // value that we should have after the other code runs without actually
    // drawing anything right now
    int gy2_old = gy2;
    if(dataLabel().length() > 0) {
        fm = QFontMetrics(dataLabelFont());
        gy2 -= fm.height();
    }
    fm = QFontMetrics(dataFont());
    QMapIterator<int, GReference> dlit = _data.begin();
    double tlh = 0.0;
    for(dlit = _data.begin(); dlit != _data.end(); ++dlit) {
        tlh = QMAX(sin45deg * fm.width(dlit.data().first), tlh);
    }
    // don't change this variable as we use it later
    int th = (tlh == 0.0 ? 0 : (int)(tlh + (fm.height() * sin45deg)) + 2);
    gy2 -= th;


    // get the dimensions of the value label then draw it
    if(valueLabel().length() > 0) {
        fm = QFontMetrics(valueLabelFont());
        //brect = fm.boundingRect(valueLabel());
        paint.setFont(valueLabelFont());
        paint.save();
        paint.rotate(-90);
        paint.drawText(-gy2, gx1, gy2 - gy1, fm.height(), valueLabelAlignment(), valueLabel());
        paint.restore();
        gx1 += fm.height();
    }

    fm = QFontMetrics(valueFont());

    QString min_str = QString().sprintf("%-.0f",minValue());
    QString org_str = ( minValue() == 0.0 ? QString::null : "0" );
    QString max_str = QString().sprintf("%-.0f",maxValue());

    int width = QMAX(fm.width(min_str), fm.width(max_str));
    if(org_str.length() > 0) width = QMAX(width, fm.width(org_str));

    gx1 += width;

    int gy_max = gy1;
    int gy_min = gy2 - 1;
    int gy_org = gy_min;

    paint.setFont(valueFont());
    int tfa = Qt::AlignTop | Qt::AlignRight;
    paint.drawText(gx1 - fm.width(min_str), gy_min, fm.width(min_str), fm.height(), tfa, min_str);
    paint.drawLine(gx1 - 3, gy_min, gx1 + 2, gy_min);
    paint.drawText(gx1 - fm.width(max_str), gy_max, fm.width(max_str), fm.height(), tfa, max_str);
    paint.drawLine(gx1 - 3, gy_max, gx1 + 2, gy_max);
    int gheight = gy2 - gy1;
    double grng = maxValue() - minValue();
    if(org_str.length() > 0) {
        double perc = (0 - minValue()) / grng;
        gy_org = gy2 - (int)(perc * (double)gheight);
        paint.drawText(gx1 - fm.width(org_str), gy_org, fm.width(org_str), fm.height(), tfa, org_str);
        paint.drawLine(gx1 - 3, gy_org, gx1 + 2, gy_org);
    }

    gx1 += 3;

    // put the old value back so all the code to come draw correctly!
    gy2 = gy2_old;

    // get the dimensions of the data label then draw it
    if(dataLabel().length() > 0) {
        fm = QFontMetrics(dataLabelFont());
        //brect = fm.boundingRect(dataLabel());
        paint.setFont(dataLabelFont());
        gy2 -= fm.height();
        paint.drawText(gx1, gy2, gx2 - gx1, fm.height(), dataLabelAlignment(), dataLabel());
    }

    gy2 -= th;

    int ref_cnt = _data.count();
    int gwidth = gx2 - gx1;
    gheight = gy2 - gy1;

    if(ref_cnt > 0) {
        paint.save();
        fm = QFontMetrics(dataFont());
        paint.setFont(dataFont());
        int refwidth = QMAX(1, gwidth / ref_cnt);
        int buf = (int)(refwidth / 5);
        int buf2 = buf * 2;
        QMapIterator<int, GReference> rit;
        int pos = gx1 + (int)((gwidth - (refwidth * ref_cnt)) / 2);
        int bar_height;
        int fmheight = fm.height();
        int fmheight_div_2 = fmheight / 2;
        int refwidth_div_2 = refwidth / 2;
        int label_offset = (int)(fmheight_div_2 * cos45deg);
        int last_label_at = -1000;
        QMap<int, double> last_map;
        QMap<int, double> this_map;
        for(rit = _data.begin(); rit != _data.end(); ++rit ) {
            GReference ref = rit.data();
            QString label = ref.first;
            if(label.length() > 0 && ((pos + refwidth_div_2) - last_label_at) > ((label_offset * 2) + 1)) {
                last_label_at = pos + refwidth_div_2;
                int lx = (int)(((pos + refwidth_div_2) * cos45deg) - ((gy2 + label_offset) * sin45deg));
                int ly = (int)(((pos + refwidth_div_2) * sin45deg) + ((gy2 + label_offset) * cos45deg));
                int fmwidth = fm.width(label);
                paint.save();
                paint.rotate(-45);
                paint.drawText(lx - fmwidth, ly - fmheight_div_2, fmwidth, fmheight, Qt::AlignRight | Qt::AlignTop, label);
                paint.restore();
            }

            QMapIterator<int, double> sit;
            paint.save();
            if(drawBars() == TRUE) {
                TSetValue tval;
                QMap<double, TSetValue> sort_map;
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit ) {
                    if(sit.data() != 0.0 && _setStyle[sit.key()].bar == TRUE) {
                        tval.first = sit.key();
                        tval.second = sit.data();
                        sort_map[(tval.second < 0.0 ? minValue() : maxValue()) - (tval.second < 0.0 ? -tval.second : tval.second)] = tval;
                    }
                }
                QMapIterator<double, TSetValue> it;
                for(it = sort_map.begin(); it != sort_map.end(); ++it) {
                    tval = it.data();
                    if(tval.second != 0.0) {
                        if(tval.second < 0) {
                            bar_height = (int)((tval.second / minValue()) * (gy_org - gy_min));
                        } else {
                            bar_height = (int)((tval.second / maxValue()) * (gy_org - gy_max));
                        } 
                        paint.fillRect(pos + buf, gy_org - bar_height, refwidth - buf2, bar_height, getSetColor(tval.first));
                    }
                }
            }
            if(drawLines() == TRUE) {
                this_map.clear();
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) {
                    if(_setStyle[sit.key()].line == TRUE) {
                        this_map[sit.key()] = sit.data();
                        if(last_map.contains(sit.key())) {
                            paint.setPen(getSetColor(sit.key()));
                            double old_val = last_map[sit.key()];
                            double new_val = sit.data();
                            int ly1;
                            if(old_val < 0.0) ly1 = (int)((old_val / minValue()) * (gy_org - gy_min));
                            else              ly1 = (int)((old_val / maxValue()) * (gy_org - gy_max));
                            ly1 = gy_org - ly1;
                            int lx1 = pos - refwidth_div_2;
                            int ly2;
                            if(new_val < 0.0) ly2 = (int)((new_val / minValue()) * (gy_org - gy_min));
                            else              ly2 = (int)((new_val / maxValue()) * (gy_org - gy_max));
                            ly2 = gy_org - ly2;
                            int lx2 = pos + refwidth_div_2;
                            paint.drawLine(lx1, ly1, lx2, ly2);
                        }
                    }
                }
                last_map = this_map;
            }
            if(drawPoints() == TRUE) {
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) {
                    if(_setStyle[sit.key()].point == TRUE) {
                        paint.setBrush(getSetColor(sit.key()));
                        paint.setPen(QColor(0,0,0));
                        int ly1;
                        if(sit.data() < 0.0) ly1 = (int)((sit.data() / minValue()) * (gy_org - gy_min));
                        else                 ly1 = (int)((sit.data() / maxValue()) * (gy_org - gy_max));
                        ly1 = gy_org - ly1;
                        int lx1 = pos + refwidth_div_2;
                        paint.drawEllipse(lx1 - 2, ly1 - 2, 5, 5);
                    }
                }
            }
            paint.restore();
            pos += refwidth;
        }
        paint.restore();
    }

    paint.drawLine(gx1, gy_org, gx2 - 1, gy_org);
    paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);


    // Now that we are done return the paint device back to the state
    // it was when we started to mess with it
    paint.restore();
}
    //__________________________________________________
    Configuration::Configuration( KConfigGroup group )
    {

        // used to set default values when entries are not found in kconfig
        Configuration defaultConfiguration;

        // title alignment
        setTitleAlignment( titleAlignment(
            group.readEntry( OxygenConfig::TITLE_ALIGNMENT,
            defaultConfiguration.titleAlignmentName( false ) ), false ) );

        // center title on full width
        setCenterTitleOnFullWidth( group.readEntry( OxygenConfig::CENTER_TITLE_ON_FULL_WIDTH,
            defaultConfiguration.centerTitleOnFullWidth() ) );

        // button size
        setButtonSize( buttonSize(
            group.readEntry( OxygenConfig::BUTTON_SIZE,
            defaultConfiguration.buttonSizeName( false ) ), false ) );

        // frame border
        setFrameBorder( frameBorder(
            group.readEntry( OxygenConfig::FRAME_BORDER,
            defaultConfiguration.frameBorderName( false ) ), false ) );

        // blend color
        setBlendColor( blendColor(
            group.readEntry( OxygenConfig::BLEND_COLOR,
            defaultConfiguration.blendColorName( false ) ), false ) );

        // size grip
        setSizeGripMode( sizeGripMode(
            group.readEntry( OxygenConfig::SIZE_GRIP_MODE,
            defaultConfiguration.sizeGripModeName( false ) ), false ) );

        // separator mode
        if( !group.readEntry( OxygenConfig::DRAW_SEPARATOR, defaultConfiguration.separatorMode() != SeparatorNever ) )
        {

            setSeparatorMode( SeparatorNever );

        } else if( group.readEntry( OxygenConfig::SEPARATOR_ACTIVE_ONLY, defaultConfiguration.separatorMode() == SeparatorActive ) ) {

            setSeparatorMode( SeparatorActive );

        } else setSeparatorMode( SeparatorAlways );

        // title outline
        setDrawTitleOutline( group.readEntry(
            OxygenConfig::DRAW_TITLE_OUTLINE,
            defaultConfiguration.drawTitleOutline() ) );

        // hide title bar
        setHideTitleBar( group.readEntry(
            OxygenConfig::HIDE_TITLEBAR,
            defaultConfiguration.hideTitleBar() ) );

        // drop shadows
        setUseDropShadows( group.readEntry(
            OxygenConfig::USE_DROP_SHADOWS,
            defaultConfiguration.useDropShadows() ) );

        // oxygen shadows
        setUseOxygenShadows( group.readEntry(
            OxygenConfig::USE_OXYGEN_SHADOWS,
            defaultConfiguration.useOxygenShadows() ) );

        // transparency
        setTransparencyEnabled( group.readEntry(
            OxygenConfig::TRANSPARENCY_ENABLED,
            defaultConfiguration.transparencyEnabled() ) );

        // close from menu button
        setCloseFromMenuButton( group.readEntry(
            OxygenConfig::CLOSE_FROM_MENU_BUTTON,
            defaultConfiguration.closeFromMenuButton() ) );

        // buttonSpacing
        setUseNarrowButtonSpacing( group.readEntry(
            OxygenConfig::NARROW_BUTTON_SPACING,
            defaultConfiguration.useNarrowButtonSpacing() ) );

        // background opacity
        /*
        this is the decoration specific value
        it is overwritten by the style ("common") opacity, if opacityFromStyle is set to true
        */
        setBackgroundOpacity(
            group.readEntry( OxygenConfig::BACKGROUND_OPACITY,
            defaultConfiguration.backgroundOpacity() ) );

        setOpacityFromStyle(
            group.readEntry( OxygenConfig::OPACITY_FROM_STYLE,
            defaultConfiguration.opacityFromStyle() ) );

        // extended window border
        setUseExtendedWindowBorder( group.readEntry(
            OxygenConfig::EXTENDED_WINDOW_BORDERS,
            defaultConfiguration.useExtendedWindowBorder() ) );

        // animations
        setAnimationsEnabled( group.readEntry(
            OxygenConfig::ANIMATIONS_ENABLED,
            defaultConfiguration.animationsEnabled() ) );

        setButtonAnimationsEnabled( group.readEntry(
            OxygenConfig::BUTTON_ANIMATIONS_ENABLED,
            defaultConfiguration.buttonAnimationsEnabled() ) );

        setTitleAnimationsEnabled( group.readEntry(
            OxygenConfig::TITLE_ANIMATIONS_ENABLED,
            defaultConfiguration.titleAnimationsEnabled() ) );

        setShadowAnimationsEnabled( group.readEntry(
            OxygenConfig::SHADOW_ANIMATIONS_ENABLED,
            defaultConfiguration.shadowAnimationsEnabled() ) );

        setTabAnimationsEnabled( group.readEntry(
            OxygenConfig::TAB_ANIMATIONS_ENABLED,
            defaultConfiguration.tabAnimationsEnabled() ) );

        // animations duration
        setButtonAnimationsDuration( group.readEntry(
            OxygenConfig::BUTTON_ANIMATIONS_DURATION,
            defaultConfiguration.buttonAnimationsDuration() ) );

        setTitleAnimationsDuration( group.readEntry(
            OxygenConfig::TITLE_ANIMATIONS_DURATION,
            defaultConfiguration.titleAnimationsDuration() ) );

        setShadowAnimationsDuration( group.readEntry(
            OxygenConfig::SHADOW_ANIMATIONS_DURATION,
            defaultConfiguration.shadowAnimationsDuration() ) );

        setTabAnimationsDuration( group.readEntry(
            OxygenConfig::TAB_ANIMATIONS_DURATION,
            defaultConfiguration.tabAnimationsDuration() ) );

    }