Esempio n. 1
0
void DateTimeGroup::updateSize()
{
	Plasma::FormFactor f = formFactor();
	
	if (f != Plasma::Vertical && f != Plasma::Horizontal) {
		const QFontMetricsF metrics(KGlobalSettings::smallestReadableFont());
		setMinimumSize(metrics.size(Qt::TextSingleLine, dtg));
	}
	
	int aspect = 12;
	
	int w, h;
	
	w = (int)(contentsRect().height() * aspect);
	h = (int)(contentsRect().width() / aspect);
	
	if (f == Plasma::Horizontal) {
		setMinimumSize(QSize(w, 0));
	} else {
		setMinimumSize(QSize(0, h));
	}
	
	setPreferredSize(QSize(w, h));
	emit sizeHintChanged(Qt::PreferredSize);
	
	if (m_isDefaultFont) {
		expandFontToMax(m_plainDateTimeGroupFont, dtg);
	}
	
	generatePixmap();
}
Esempio n. 2
0
void KeyboardLayoutWidget::setKeyboard(XkbComponentNamesPtr names)
{
    release();
    if (xkb)
        XkbFreeKeyboard(xkb, 0, TRUE);
    if (names) {
        xkb = XkbGetKeyboardByName (QX11Info::display(), XkbUseCoreKbd,
                      names, 0,
                      XkbGBN_GeometryMask |
                      XkbGBN_KeyNamesMask |
                      XkbGBN_OtherNamesMask |
                      XkbGBN_ClientSymbolsMask |
                      XkbGBN_IndicatorMapMask, FALSE);
        xkbOnDisplay = FALSE;
    } else {
        xkb = XkbGetKeyboard (QX11Info::display(),
                           XkbGBN_GeometryMask |
                           XkbGBN_KeyNamesMask |
                           XkbGBN_OtherNamesMask |
                           XkbGBN_SymbolsMask |
                           XkbGBN_IndicatorMapMask,
                           XkbUseCoreKbd);
        XkbGetNames (QX11Info::display(), XkbAllNamesMask, xkb);
        xkbOnDisplay = TRUE;
    }

    if (xkb == NULL)
        return;

    alloc ();
    init();
    initColors();
    generatePixmap(true);
    repaint();
}
Esempio n. 3
0
// In case time format has changed, e.g. from 24h to 12h format.
void Clock::updateClock(int category)
{
    if (category != KGlobalSettings::SETTINGS_LOCALE) {
        return;
    }

    generatePixmap();
    update();
}
void TTKCircleProgressWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QPixmap pixmap;
    if(!QPixmapCache::find(key(), pixmap))
    {
        pixmap = generatePixmap();
        QPixmapCache::insert(key(), pixmap);
    }

    QPainter painter(this);
    painter.drawPixmap( 0.5 * ( width() - pixmap.width() ), 0.5 * ( height() - pixmap.height() ), pixmap );
}
Esempio n. 5
0
void DateTimeGroup::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
{
	Q_UNUSED(source);
	QTime m_time = data["Time"].toTime();
	KConfigGroup cg= config();
	kDebug()<<cg.entryMap();

	if ((m_showSeconds && m_time.second() != lastTimeSeen().second()) ||
		m_time.minute() != lastTimeSeen().minute()) {
		setDtg(data);
		m_lastTimeSeen = data["Time"].toTime();
		generatePixmap();
		update();
	}
}
Esempio n. 6
0
void KeyboardApplet::constraintsEvent(Plasma::Constraints constraints)
{
    if (constraints & Plasma::FormFactorConstraint) {
        int iconSize;
        if (formFactor() == Plasma::Planar ||
                formFactor() == Plasma::MediaCenter) {
            iconSize = IconSize(KIconLoader::Desktop);
        } else {
            iconSize = IconSize(KIconLoader::Small);
        }
        setMinimumSize(iconSize, iconSize);
    }
    if (constraints & Plasma::SizeConstraint) {
        generatePixmap();
    }
}
Esempio n. 7
0
void Clock::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
{
    Q_UNUSED(source);
    m_time = data["Time"].toTime();
    m_date = data["Date"].toDate();

    // avoid unnecessary repaints
    if ((m_showSeconds && m_time.second() != lastTimeSeen().second()) ||
        m_time.minute() != lastTimeSeen().minute()) {

        if (Plasma::ToolTipManager::self()->isVisible(this)) {
            updateTipContent();
        }

        updateClockApplet(data);
        generatePixmap();
        update();
    }
}
Esempio n. 8
0
//#---------------------------------------------------------------------------#
//#------- PROTECTED ---------------------------------------------------------#
//#---------------------------------------------------------------------------#
void PixmapMatrix::paintEvent(QPaintEvent *event)
{
    if (!this->m_relation)
        return;


    QPixmap pixmap;
    if (!QPixmapCache::find(this->m_cacheId, &pixmap)) {
        pixmap = generatePixmap();
        QPixmapCache::insert(this->m_cacheId, pixmap);
    }



    QPainter painter;
    painter.begin(this);
    painter.drawPixmap(event->rect(), pixmap);
    painter.end();
}
Esempio n. 9
0
void KeyboardLayoutWidget::focusOutEvent(QFocusEvent* event)
{
    if (!xkb) {
        QWidget::focusOutEvent(event);
        return;
    }

    bool update = false;
    for (int i = xkb->min_key_code; i <= xkb->max_key_code; i ++) {
        if (keys[i].pressed) {
            update = true;
            keys[i].pressed = false;
        }
    }

    if (update) {
        generatePixmap(true);
        repaint();
    }
    QWidget::focusOutEvent(event);
}
Esempio n. 10
0
void BusyIndicator::paintEvent(QPaintEvent *)
{
    QString key = QString("%1:%2:%3:%4:%5")
            .arg(metaObject()->className())
            .arg(width())
            .arg(height())
            .arg(startAngle)
            .arg(m_style);

    QPixmap pixmap;
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    int side = qMin(width(), height());

    if(!QPixmapCache::find(key, &pixmap)) {
        pixmap = generatePixmap(side);
        QPixmapCache::insert(key, pixmap);
    }

    painter.translate(width() / 2 - side / 2, height() / 2 - side / 2);

    painter.drawPixmap(0, 0, side, side, pixmap);
}
Esempio n. 11
0
QImage PictureBase::generateImage(const QSize& size)
{
    return generatePixmap(size, true).toImage();
}
Esempio n. 12
0
void Clock::clockConfigAccepted()
{
    KConfigGroup cg = config();

    m_showTimezone = ui.showTimeZone->isChecked();
    cg.writeEntry("showTimezone", m_showTimezone);

    if (m_isDefaultFont && ui.plainClockFont->currentFont() != m_plainClockFont) {
        m_isDefaultFont = false;
    }
    m_plainClockFont = ui.plainClockFont->currentFont();

    //We need this to happen before we disconnect/reconnect sources to ensure
    //that the update interval is set properly.
    if (m_showSeconds != ui.secondsCheckbox->isChecked()) {
        m_showSeconds = !m_showSeconds;
        cg.writeEntry("showSeconds", m_showSeconds);

        if (m_showSeconds) {
            //We don't need to cache the applet if it update every second
            setCacheMode(QGraphicsItem::NoCache);
        } else {
            setCacheMode(QGraphicsItem::DeviceCoordinateCache);
        }

        changeEngineTimezone(currentTimezone(), currentTimezone());
    }

    m_dateStyle = ui.dateStyle->currentIndex();
    cg.writeEntry("dateStyle", m_dateStyle);

    m_showSeconds = ui.secondsCheckbox->checkState() == Qt::Checked;
    cg.writeEntry("showSeconds", m_showSeconds);

    m_useCustomColor = ui.useCustomColor->isChecked();
    cg.writeEntry("useCustomColor", m_useCustomColor);
    if (m_useCustomColor) {
        m_plainClockColor = ui.plainClockColor->color();
        cg.writeEntry("plainClockColor", m_plainClockColor);
        m_pixmap = QPixmap();
        delete m_svg;
        m_svg = 0;
    } else {
        m_plainClockColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
    }

    m_useCustomShadowColor = ui.useCustomShadowColor->isChecked();
    cg.writeEntry("useCustomShadowColor", m_useCustomShadowColor);
    if (m_useCustomShadowColor) {
        m_plainClockShadowColor = ui.plainClockShadowColor->color();
        cg.writeEntry("plainClockShadowColor", m_plainClockShadowColor);
    } else {
        m_plainClockShadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
    }
    m_drawShadow = ui.drawShadow->isChecked();
    cg.writeEntry("plainClockDrawShadow", m_drawShadow);

    m_plainClockFont.setBold(ui.plainClockFontBold->checkState() == Qt::Checked);
    m_plainClockFont.setItalic(ui.plainClockFontItalic->checkState() == Qt::Checked);
    cg.writeEntry("plainClockFont", m_plainClockFont);

    constraintsEvent(Plasma::SizeConstraint);
    generatePixmap();
    update();
    emit sizeHintChanged(Qt::PreferredSize);
    emit configNeedsSaving();
}
Esempio n. 13
0
void Clock::updateSize()
{
    Plasma::FormFactor f = formFactor();

    if (f != Plasma::Vertical && f != Plasma::Horizontal) {
        const QFontMetricsF metrics(KGlobalSettings::smallestReadableFont());
        // calculates based on size of "23:59"!
        const QString timeString = KGlobal::locale()->formatTime(QTime(23, 59), m_showSeconds);
        setMinimumSize(metrics.size(Qt::TextSingleLine, timeString));
    }

    // more magic numbers
    int aspect = 2;
    if (m_showSeconds) {
        aspect = 3;
    }

    int w, h;
    if (m_dateStyle || showTimezone()) {
        const QFont f(KGlobalSettings::smallestReadableFont());
        const QFontMetrics metrics(f);
        // if there's enough vertical space, wrap the words
        if (contentsRect().height() < f.pointSize() * 6) {
            QSize s = metrics.size(Qt::TextSingleLine, m_dateString);
            w = s.width() + metrics.width(" ");
            h = f.pointSize();
            //kDebug(96669) << "uS: singleline" << w;
        } else {
            QSize s = metrics.size(Qt::TextWordWrap, m_dateString);
            w = s.width();
            h = f.pointSize();
            //kDebug(96669) << "uS: wordwrap" << w;
        }

        if (!m_dateTimezoneBesides) {
            w = qMax(w, (int)(contentsRect().height() * aspect));
            h = h+(int)(contentsRect().width() / aspect);
        } else {
            w = w+(int)(contentsRect().height() * aspect);
            h = qMax(h, (int)(contentsRect().width() / aspect));
        }
    } else {
        w = (int)(contentsRect().height() * aspect);
        h = (int)(contentsRect().width() / aspect);
    }

    if (f == Plasma::Horizontal) {
        // We have a fixed height, set some sensible width
        setMinimumSize(QSize(w, 0));
        //kDebug() << "DR" << m_dateRect.width() << "CR" << contentsRect().height() * aspect;
        // kDebug(96669) << contentsRect();
    } else {
        // We have a fixed width, set some sensible height
        setMinimumSize(QSize(0, h));
    }

    setPreferredSize(QSize(w, h));
    emit sizeHintChanged(Qt::PreferredSize);
    //kDebug(96669) << "minZize: " << minimumSize() << preferredSize();

    if (m_isDefaultFont) {
        const QString fakeTimeString = KGlobal::locale()->formatTime(QTime(23,59,59), m_showSeconds);
        expandFontToMax(m_plainClockFont, fakeTimeString);
    }

    generatePixmap();
    update();
}
Esempio n. 14
0
void KeyboardApplet::layoutChanged()
{
    generatePixmap();
    updateTooltip();
    update();
}
Esempio n. 15
0
void VolumeSlider::generatePixmaps()
{
    pixmaps[0]=generatePixmap(false);
    pixmaps[1]=generatePixmap(true);
}
Esempio n. 16
0
void DateTimeGroup::configAccepted()
{
	bool m_formatChanged;
	KConfigGroup cg = config();
	
	if (m_isDefaultFont && ui.plainDateTimeGroupFont->currentFont() != m_plainDateTimeGroupFont) {
		m_isDefaultFont = false;
	}
	
	m_plainDateTimeGroupFont = ui.plainDateTimeGroupFont->currentFont();
	
	if(m_sAfterDay!=ui.sAfterDay->isChecked()){
		m_sAfterDay = !m_sAfterDay;
		cg.writeEntry("sAfterDay", m_sAfterDay);
		m_formatChanged=true;
	}
	if(m_sAfterHour!=ui.sAfterHour->isChecked()){
		m_sAfterHour = !m_sAfterHour;
		cg.writeEntry("sAfterHour", m_sAfterHour);
		m_formatChanged=true;
	}
	
	if(m_sAfterMinute!=ui.sAfterMinute->isChecked()){
		m_sAfterMinute =!m_sAfterMinute;
		cg.writeEntry("sAfterMinute", m_sAfterMinute);	
		m_formatChanged=true;
	}
	
	if(m_sAfterSecond!=ui.sAfterSecond->isChecked()){
		m_sAfterSecond =!m_sAfterSecond;
		cg.writeEntry("sAfterSecond", m_sAfterSecond);
		m_formatChanged=true;
	}
	
	if(m_sAfterTimeZone!=ui.sAfterTimeZone->isChecked()){
		m_sAfterTimeZone = !m_sAfterTimeZone;
		cg.writeEntry("sAfterTimeZone", m_sAfterTimeZone);
		m_formatChanged=true;
	}
	
	if(m_sAfterMonth!=ui.sAfterMonth->isChecked()){
		m_sAfterMonth = !m_sAfterMonth;
		cg.writeEntry("sAfterMonth", m_sAfterMonth);
		m_formatChanged=true;
	}
	if(m_rounded!=timezonesUi.fullLetters->isChecked()){
		m_rounded = !m_rounded;
		cg.writeEntry("rounded", m_rounded);
		m_formatChanged=true;
	}
	
	if(m_natoOperation!= ui.natoOperation->isChecked()){
		m_natoOperation=!m_natoOperation;
		cg.writeEntry("natoOperation", m_natoOperation);
		tzBefNatoOp=cg.readEntry("currentTimezone");
		changeEngineTimezone( (m_natoOperation?"UTC":tzBefNatoOp)); 
	}

	if(m_local!= ui.localTime->isChecked()){
		m_local=!m_local;
		cg.writeEntry("localTime", m_local);
		tzBefNatoOp=m_natoOperation?"UTC":cg.readEntry("currentTimezone");
		changeEngineTimezone( (m_local?"Local":tzBefNatoOp)); 
	}
	if (timezonesUi.timeZones->selection()!=curtz && !m_local && !m_natoOperation) {
		changeEngineTimezone(timezonesUi.timeZones->selection());
		cg.writeEntry("currentTimezone", timezonesUi.timeZones->selection());
	}
	if(ui.shortFormat->isChecked()&&m_format!=1){
		int oldm_format=m_format;
		m_format=1;
		m_formatChanged=false;
		if(oldm_format==0)
			setDtg(dataEngine("datetimegroup")->query(currentTimezone()));
	}
	else if(ui.longFormat->isChecked()&&m_format!=2){
		m_format=2;
	}
	else if(ui.stanFormat->isChecked()&&m_format!=0){
		int oldm_format=m_format;
		m_format=0;
		m_formatChanged=false;
		if(oldm_format==1)
			setDtg(dataEngine("datetimegroup")->query(currentTimezone()));
	}
	
	cg.writeEntry("format",m_format);
	if (m_showSeconds != (m_format==2)) {
		m_showSeconds = !m_showSeconds;
		
		if (m_showSeconds) {
			//We don't need to cache the applet if it update every second
			setCacheMode(QGraphicsItem::NoCache);
		} else {
			setCacheMode(QGraphicsItem::DeviceCoordinateCache);
		}
		
		changeEngineTimezone(currentTimezone());
	}
	if(m_formatChanged)
		setDtg(dataEngine("datetimegroup")->query(currentTimezone()));
		
	m_useCustomColor = ui.useCustomColor->isChecked();
	cg.writeEntry("useCustomColor", m_useCustomColor);
	if (m_useCustomColor) {
		m_plainDateTimeGroupColor = ui.plainDateTimeGroupColor->color();
		cg.writeEntry("plainDateTimeGroupColor", m_plainDateTimeGroupColor);
		m_pixmap = QPixmap();
		delete m_svg;
		m_svg = 0;
	} else {
		m_plainDateTimeGroupColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
	}
	
	m_useCustomShadowColor = ui.useCustomShadowColor->isChecked();
	cg.writeEntry("useCustomShadowColor", m_useCustomShadowColor);
	if (m_useCustomShadowColor) {
		m_plainDateTimeGroupShadowColor = ui.plainDateTimeGroupShadowColor->color();
		cg.writeEntry("plainDateTimeGroupShadowColor", m_plainDateTimeGroupShadowColor);
	} else {
		m_plainDateTimeGroupShadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
	}
	m_drawShadow = ui.drawShadow->isChecked();
	cg.writeEntry("plainDateTimeGroupDrawShadow", m_drawShadow);
	
	m_plainDateTimeGroupFont.setBold(ui.plainDateTimeGroupFontBold->checkState() == Qt::Checked);
	m_plainDateTimeGroupFont.setItalic(ui.plainDateTimeGroupFontItalic->checkState() == Qt::Checked);
	cg.writeEntry("plainDateTimeGroupFont", m_plainDateTimeGroupFont);
	
	constraintsEvent(Plasma::SizeConstraint);
	generatePixmap();
	update();
	
	emit sizeHintChanged(Qt::PreferredSize);
	emit configNeedsSaving();
}