int main () { int left, right, top, bottom, /* Cell index boundaries */ row, column; /* Current cell indices */ float delta, halfDelta, /* Cell sizes */ area, halfArea, /* Cell areas */ y, z; /* Cell center location */ /* Initialize index values */ left = 1; right = SUBDIV; top = 1; bottom = (SUBDIV + 1) / 2; row = 1; column = 1; /* Initialize cell values */ delta = (MAX - MIN) / SUBDIV; halfDelta = delta / 2.f; area = delta * delta; halfArea = area / 2.f; y = z = (float)MAX - halfDelta; /* Calculate and display delta form factors */ for (row = top; row <= bottom; row++) { for (column = left; column < right; column++) { printf("Cell(%0d,%0d) = %f\n", row, column, formFactor(y, z, area)); y -= delta; } printf("Cell(%0d,%0d) = %f\n", row, column, formFactor(y+halfDelta, z+halfDelta, halfArea)); left++; right--; y = z -= delta; } }
void NowPlaying::constraintsEvent(Plasma::Constraints constraints) { if (constraints & Plasma::FormFactorConstraint) { switch (formFactor()) { case Plasma::Horizontal: layoutHorizontal(); break; case Plasma::Vertical: layoutHorizontal(); // FIXME break; default: layoutPlanar(); break; } } if (constraints & Plasma::SizeConstraint) { switch (formFactor()) { case Plasma::Horizontal: setPreferredSize(contentsRect().height() * 2, contentsRect().height()); break; case Plasma::Vertical: setPreferredSize(contentsRect().width(), contentsRect().width() / 2); break; default: break; } } }
void GraphicalTimetableLine::createTooltip( Departure *departure ) { if ( isPopupShowing() || (formFactor() != Plasma::Horizontal && formFactor() != Plasma::Vertical) ) { return; } Plasma::ToolTipContent tooltipData; tooltipData.setMainText( i18nc("@info", "Public Transport") ); if ( m_departures.isEmpty() ) { tooltipData.setSubText( i18nc("@info", "View departures for public transport") ); } else { QList<DepartureData> dataList = departure ? departure->departureData() : m_departures.first()->departureData(); if ( dataList.count() == 1 ) { // Signle departure item hovered DepartureData data = dataList.first(); tooltipData.setSubText( i18n("Line %1 (%2) %3", data.transportLine, data.target, KGlobal::locale()->formatTime(data.time.time())) ); } else { // Multiple departure items hovered QString text; foreach ( const DepartureData &data, dataList ) { text.append( i18n("Line %1 (%2) %3\n", data.transportLine, data.target, KGlobal::locale()->formatTime(data.time.time())) ); } if ( text.endsWith('\n') ) { text.remove( text.length() - 1, 1 ); } tooltipData.setSubText( text ); } }
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(); }
void Clock::prepareFont(QFont &font, QRect &rect, const QString &text, bool singleline) { QRect tmpRect; bool first = true; const int smallest = KGlobalSettings::smallestReadableFont().pointSize(); // Starting with the given font, decrease its size until it'll fit in the // given rect allowing wrapping where possible do { if (first) { first = false; } else { font.setPointSize(qMax(smallest, font.pointSize() - 1)); } const QFontMetrics fm(font); int flags = (singleline || ((formFactor() == Plasma::Horizontal) && (contentsRect().height() < font.pointSize()*6))) ? Qt::TextSingleLine : Qt::TextWordWrap; tmpRect = fm.boundingRect(rect, flags, text); } while (font.pointSize() > smallest && (tmpRect.width() > rect.width() || tmpRect.height() > rect.height())); rect = tmpRect; }
std::complex<double> FormFactorDecorator::evaluate( const DataPoint &point, unsigned int pos) const { double ff = formFactor(point.KinematicVariableList[pos], Daughter1Mass->value(), Daughter2Mass->value(), (unsigned int)L, MesonRadius->value(), FFType); return ff * UndecoratedBreitWigner->evaluate(point, pos); }
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(); } }
void Clock::constraintsEvent(Plasma::Constraints constraints) { ClockApplet::constraintsEvent(constraints); if (constraints & Plasma::SizeConstraint) { invalidateCache(); } if (constraints & Plasma::FormFactorConstraint) { if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { setPreferredSize(256, 256); } else { setPreferredSize(-1, -1); } } }
void NowPlaying::init() { switch (formFactor()) { case Plasma::Horizontal: layoutHorizontal(); break; case Plasma::Vertical: layoutHorizontal(); // FIXME break; default: layoutPlanar(); break; } Plasma::DataEngine* nowPlayingEngine = dataEngine("nowplaying"); if (nowPlayingEngine) { connect(nowPlayingEngine, SIGNAL(sourceAdded(QString)), SLOT(playerAdded(QString))); connect(nowPlayingEngine, SIGNAL(sourceRemoved(QString)), SLOT(playerRemoved(QString))); findPlayer(); } else { kDebug() << "Now Playing engine not found"; } }
void ITmagesApplet::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) { Q_UNUSED (option); // for normal view if (formFactor()==0) setMinimumSize(100,100); else if (formFactor()==2) setMinimumSize(5,5); // ITmages logo render p->setRenderHint(QPainter::SmoothPixmapTransform); p->setRenderHint(QPainter::Antialiasing); image->resize((int)contentsRect.width(), (int)contentsRect.height()); image->paint(p, (int)contentsRect.left(), (int)contentsRect.top()); //p->restore(); //it's needed, theoretically, but I don't know why... }
void Bubble::constraintsEvent(Plasma::Constraints constraints) { Plasma::Applet::constraintsEvent(constraints); if (constraints & Plasma::FormFactorConstraint) { if (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical) { setPreferredSize(-1,-1); } else { setPreferredSize(150, 150); } } if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { setMinimumSize(30,30); } else { setMinimumSize(0,0); } }
void IconApplet::constraintsEvent(Plasma::Constraints constraints) { setBackgroundHints(NoBackground); if (constraints & Plasma::FormFactorConstraint) { disconnect(m_icon, SIGNAL(activated()), this, SLOT(openUrl())); disconnect(m_icon, SIGNAL(clicked()), this, SLOT(openUrl())); if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { connect(m_icon, SIGNAL(activated()), this, SLOT(openUrl())); if (!m_lastFreeSize.isEmpty()) { resize(m_lastFreeSize); } m_icon->setText(m_text); Plasma::ToolTipManager::self()->unregisterWidget(m_icon); m_icon->setDrawBackground(true); } else { //in the panel the icon behaves like a button connect(m_icon, SIGNAL(clicked()), this, SLOT(openUrl())); m_icon->setText(QString()); Plasma::ToolTipContent data(m_text, m_genericName, m_icon->icon()); Plasma::ToolTipManager::self()->setContent(m_icon, data); m_icon->setDrawBackground(false); if (!m_lastFreeSize.isEmpty()) { config().writeEntry("LastFreeSize", size().toSize()); emit configNeedsSaving(); } } } if (constraints & Plasma::SizeConstraint && !m_lastFreeSize.isEmpty() && (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter)) { m_lastFreeSize = size().toSize(); } if (constraints & Plasma::StartupCompletedConstraint) { m_lastFreeSize = config().readEntry("LastFreeSize", size().toSize()); } }
void IconApplet::saveState(KConfigGroup &cg) const { cg.writeEntry("Url", m_url); Plasma::FormFactor f = formFactor(); if (f == Plasma::Vertical || f == Plasma::Horizontal) { cg.readEntry("LastFreeSize", m_lastFreeSize); } else { cg.readEntry("LastFreeSize", size()); } }
QSizeF IconApplet::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const { if (which == Qt::PreferredSize) { int iconSize; switch (formFactor()) { case Plasma::Planar: case Plasma::MediaCenter: iconSize = IconSize(KIconLoader::Desktop); break; case Plasma::Horizontal: case Plasma::Vertical: iconSize = IconSize(KIconLoader::Panel); break; } return QSizeF(iconSize, iconSize); } return Plasma::Applet::sizeHint(which, constraint); }
void DateTimeGroup::prepareFont(QFont &font, QRect &rect, const QString &text, bool singleline) { QRect tmpRect; bool first = true; const int smallest = KGlobalSettings::smallestReadableFont().pointSize(); do { if (first) { first = false; } else { font.setPointSize(qMax(smallest, font.pointSize() - 1)); } const QFontMetrics fm(font); int flags = (singleline || ((formFactor() == Plasma::Horizontal) && (contentsRect().height() < font.pointSize()*6))) ? Qt::TextSingleLine : Qt::TextWordWrap; tmpRect = fm.boundingRect(rect, flags, text); } while (font.pointSize() > smallest && (tmpRect.width() > rect.width() || tmpRect.height() > rect.height())); rect = tmpRect; }
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(); }
void WindowList::showMenu(bool onlyCurrentDesktop) { QList<WId> windows = KWindowSystem::windows(); QList<QAction*> actionList; QList< QList<QAction*> > windowList; int amount = 0; int number = 0; qDeleteAll(m_listMenu->actions()); //m_listMenu->clear(); if (!onlyCurrentDesktop) { m_listMenu->addTitle(i18n("Actions")); QAction *unclutterAction = m_listMenu->addAction(i18n("Unclutter Windows")); QAction *cascadeAction = m_listMenu->addAction(i18n("Cascade Windows")); connect(unclutterAction, SIGNAL(triggered()), m_listMenu, SLOT(slotUnclutterWindows())); connect(cascadeAction, SIGNAL(triggered()), m_listMenu, SLOT(slotCascadeWindows())); } for (int i = 0; i <= KWindowSystem::numberOfDesktops(); ++i) { windowList.append(QList<QAction*>()); } for (int i = 0; i < windows.count(); ++i) { KWindowInfo window = KWindowSystem::windowInfo(windows.at(i), (NET::WMGeometry | NET::WMFrameExtents | NET::WMWindowType | NET::WMDesktop | NET::WMState | NET::XAWMState | NET::WMVisibleName)); NET::WindowType type = window.windowType(NET::NormalMask | NET::DialogMask | NET::OverrideMask | NET::UtilityMask | NET::DesktopMask | NET::DockMask | NET::TopMenuMask | NET::SplashMask | NET::ToolbarMask | NET::MenuMask); if ((onlyCurrentDesktop && !window.isOnDesktop(KWindowSystem::currentDesktop())) || type == NET::Desktop || type == NET::Dock || type == NET::TopMenu || type == NET::Splash || type == NET::Menu || type == NET::Toolbar || window.hasState(NET::SkipPager)) { windows.removeAt(i); --i; continue; } ++amount; QAction *action = new QAction(QIcon(KWindowSystem::icon(windows.at(i))), window.visibleName(), this); action->setData((unsigned long long) windows.at(i)); QString window_title = QString(action->text()); window_title.truncate(55); action->setText(window_title); QFont font = QFont(action->font()); if (window.isMinimized()) { font.setItalic(true); } else if (KWindowSystem::activeWindow() == windows.at(i)) { font.setUnderline(true); font.setBold(true); } action->setFont(font); number = ((onlyCurrentDesktop || window.onAllDesktops()) ? 0 : window.desktop()); QList<QAction*> subList = windowList.value(number); subList.append(action); windowList.replace(number, subList); } const bool useSubMenus = (!onlyCurrentDesktop && KWindowSystem::numberOfDesktops() > 1 && (amount / KWindowSystem::numberOfDesktops()) > 5); if (amount && useSubMenus) { m_listMenu->addTitle(i18n("Desktops")); } for (int i = 0; i <= KWindowSystem::numberOfDesktops(); ++i) { if (windowList.value(i).isEmpty()) { continue; } KMenu *subMenu = NULL; QAction *subMenuAction = NULL; QString title = (i ? KWindowSystem::desktopName(i) : (onlyCurrentDesktop ? i18n("Current desktop") : i18n("On all desktops"))); if (useSubMenus) { subMenuAction = m_listMenu->addAction(title); subMenu = new KMenu(m_listMenu); subMenu->installEventFilter(this); } else { m_listMenu->addTitle(title); } for (int j = 0; j < windowList.value(i).count(); ++j) { if (useSubMenus) { subMenu->addAction(windowList.value(i).value(j)); } else { m_listMenu->addAction(windowList.value(i).value(j)); } } if (useSubMenus) { subMenuAction->setMenu(subMenu); } } if (!amount) { qDeleteAll(m_listMenu->actions()); m_listMenu->clear(); QAction *noWindows = m_listMenu->addAction(i18n("No windows")); noWindows->setEnabled(false); } if (formFactor() == Plasma::Vertical || formFactor() == Plasma::Horizontal) { m_listMenu->popup(popupPosition(m_listMenu->sizeHint())); } else { m_listMenu->popup(QCursor::pos()); } }
void IconApplet::setUrl(const KUrl& url, bool fromConfigDialog) { if (!fromConfigDialog) { delete m_dialog.data(); } m_url = url; if (!m_url.protocol().isEmpty()) { m_url = KIO::NetAccess::mostLocalUrl(url, 0); } m_service = 0; disconnect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(checkService(QStringList))); m_hasDesktopFile = false; delete m_watcher; m_watcher = 0; // if local // if not a directory and executable // make desktop file // desktop file if (m_url.isLocalFile()) { m_watcher = new KDirWatch; m_watcher->addFile(m_url.toLocalFile()); connect(m_watcher, SIGNAL(deleted(QString)), this, SLOT(delayedDestroy())); QFileInfo fi(m_url.toLocalFile()); if (KDesktopFile::isDesktopFile(m_url.toLocalFile())) { m_hasDesktopFile = true; } else if (!fi.isDir() && fi.isExecutable()) { const QString suggestedName = fi.baseName(); const QString file = KService::newServicePath(false, suggestedName); KDesktopFile df(file); KConfigGroup desktopGroup = df.desktopGroup(); desktopGroup.writeEntry("Name", suggestedName); QString entryType; desktopGroup.writeEntry("Exec", m_url.toLocalFile()); desktopGroup.writeEntry("Icon", KMimeType::iconNameForUrl(url)); desktopGroup.writeEntry("Type", "Application"); df.sync(); m_url.setPath(file); m_hasDesktopFile = true; } } if (m_hasDesktopFile) { KDesktopFile f(m_url.toLocalFile()); m_text = f.readName(); //corrupted desktop file? if (m_text.isNull()) { m_text = m_url.fileName(); } m_icon->setIcon(f.readIcon()); m_genericName = f.readGenericName(); connect(m_watcher, SIGNAL(dirty(QString)), this, SLOT(updateDesktopFile())); } else { m_text = m_url.fileName(); m_service = KService::serviceByStorageId(m_text); connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(checkService(QStringList))); if (m_service) { m_text = m_service->name(); m_icon->setIcon(m_service->icon()); } else { if (m_text.isEmpty() && m_url.isLocalFile()) { //handle special case like the / folder m_text = m_url.directory(); } else if (m_url.protocol().contains("http")) { m_text = m_url.prettyUrl(); m_text.remove(QRegExp("http://(www.)*")); } else if (m_text.isEmpty()) { m_text = m_url.prettyUrl(); if (m_text.endsWith(QLatin1String(":/"))) { m_text = m_url.protocol(); } } m_icon->setIcon(KMimeType::iconNameForUrl(url)); } } if (m_icon->icon().isNull()) { m_icon->setIcon("unknown"); } //Update the icon text (if the icon is not on a panel) if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { m_icon->setText(m_text); } else { //Update the tooltip (if the icon is on a panel) Plasma::ToolTipContent data(m_text, m_genericName, m_icon->icon()); Plasma::ToolTipManager::self()->setContent(m_icon, data); } //kDebug() << "url was" << url << "and is" << m_url; }
void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) { Q_UNUSED(option); if (!m_time.isValid() || !m_date.isValid()) { return; } p->setPen(QPen(m_plainClockColor)); p->setRenderHint(QPainter::SmoothPixmapTransform); p->setRenderHint(QPainter::Antialiasing); /* ... helps debugging contentsRect and sizing ... QColor c = QColor(Qt::blue); c.setAlphaF(.5); p->setBrush(c); p->drawRect(contentsRect); */ // Paint the date, conditionally, and let us know afterwards how much // space is left for painting the time on top of it. QRectF dateRect; const QString timeString = KGlobal::locale()->formatTime(m_time, m_showSeconds); const QString fakeTimeString = KGlobal::locale()->formatTime(QTime(23,59,59), m_showSeconds); QFont smallFont = KGlobalSettings::smallestReadableFont(); //create the string for the date and/or the timezone if (m_dateStyle || showTimezone()) { QString dateString; //Create the localized date string if needed if (m_dateStyle) { // JPL This needs a complete rewrite for l10n issues QString day = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Day, KLocale::ShortNumber); QString month = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Month, KLocale::LongNumber); if (m_dateStyle == 1) { //compact date dateString = i18nc("@label Compact date: " "%1 day in the month, %2 month number", "%1/%2", day, month); } else if (m_dateStyle == 2) { //short date dateString = KGlobal::locale()->formatDate(m_date, KLocale::ShortDate); } else if (m_dateStyle == 3) { //long date dateString = KGlobal::locale()->formatDate(m_date, KLocale::LongDate); } else if (m_dateStyle == 4) { //ISO date dateString = KGlobal::locale()->formatDate(m_date, KLocale::IsoDate); } else { //shouldn't happen dateString = KGlobal::locale()->formatDate(m_date, KLocale::ShortDate); } if (showTimezone()) { QString currentTimezone = prettyTimezone(); dateString = i18nc("@label Date with currentTimezone: " "%1 day of the week with date, %2 currentTimezone", "%1 %2", dateString, currentTimezone); } } else if (showTimezone()) { dateString = prettyTimezone(); } dateString = dateString.trimmed(); if (m_dateString != dateString) { // If this string has changed (for example due to changes in the config // we have to reset the sizing of the applet m_dateString = dateString; updateSize(); } // Check sizes // magic 10 is for very big spaces, // where there's enough space to grow without harming time space QFontMetrics fm(smallFont); if (contentsRect.height() > contentsRect.width() * 2) { //kDebug() << Plasma::Vertical << contentsRect.height() <<contentsRect.width() * 2; QRect dateRect = contentsRect; dateRect.setHeight(dateRect.width()); smallFont.setPixelSize(qMax(dateRect.height() / 2, fm.ascent())); m_dateRect = preparePainter(p, dateRect, smallFont, dateString); } else { // Find a suitable size for the date font if (formFactor() == Plasma::Vertical) { smallFont.setPixelSize(qMax(contentsRect.height()/6, fm.ascent())); } else if (formFactor() == Plasma::Horizontal) { smallFont.setPixelSize(qMax(qMin(contentsRect.height(), contentsRect.width())*2/7, fm.ascent())); //we want to write the date always on one line fm = QFontMetrics(smallFont); const int tempWidth = fm.width(dateString); if(tempWidth > contentsRect.width()){ smallFont.setPixelSize((contentsRect.width() * smallFont.pixelSize())/tempWidth); } } else { smallFont.setPixelSize(qMax(qMin(contentsRect.height(), contentsRect.width())/8, KGlobalSettings::smallestReadableFont().pointSize())); } m_dateRect = preparePainter(p, contentsRect, smallFont, dateString); } // kDebug(96669) << "m_dateRect: " << m_dateRect; const int subtitleHeight = m_dateRect.height(); const int subtitleWidth = m_dateRect.width(); // kDebug(96669) << "subtitleWitdh: " << subtitleWitdh; // kDebug(96669) << "subtitleHeight: " << subtitleHeight; if (m_dateTimezoneBesides) { //kDebug(96669) << contentsRect.height() << subtitleHeight << smallFont.pixelSize(); if (contentsRect.height() - subtitleHeight >= smallFont.pixelSize() || formFactor() != Plasma::Horizontal) { // to small to display the time on top of the date/timezone // put them side by side // kDebug(96669) << "switching to normal"; m_dateTimezoneBesides = false; dateRect = normalLayout(subtitleWidth, subtitleHeight, contentsRect); } else { dateRect = sideBySideLayout(subtitleWidth, subtitleHeight, contentsRect); } } else { /* kDebug(96669) << "checking timezone placement" << contentsRect.height() << dateRect.height() << subtitleHeight << smallFont.pixelSize() << smallFont.pointSize();*/ if (contentsRect.height() - subtitleHeight < smallFont.pixelSize() && formFactor() == Plasma::Horizontal) { // to small to display the time on top of the date/timezone // put them side by side // kDebug(96669) << "switching to s-b-s"; m_dateTimezoneBesides = true; dateRect = sideBySideLayout(subtitleWidth, subtitleHeight, contentsRect); } else { dateRect = normalLayout(subtitleWidth, subtitleHeight, contentsRect); } } } else { m_timeRect = contentsRect; } // kDebug(96669) << "timeRect: " << m_timeRect; // p->fillRect(timeRect, QBrush(QColor("red"))); // kDebug(96669) << m_time; // Choose a relatively big font size to start with m_plainClockFont.setPointSizeF(qMax(m_timeRect.height(), KGlobalSettings::smallestReadableFont().pointSize())); preparePainter(p, m_timeRect, m_plainClockFont, fakeTimeString, true); if (!m_dateString.isEmpty()) { if (m_dateTimezoneBesides) { QFontMetrics fm(m_plainClockFont); //kDebug() << dateRect << m_timeRect << fm.boundingRect(m_timeRect, Qt::AlignCenter, timeString); QRect br = fm.boundingRect(m_timeRect, Qt::AlignCenter, timeString); QFontMetrics smallfm(smallFont); dateRect.moveLeft(br.right() + qMin(0, br.left()) + smallfm.width(" ")); } // When we're relatively low, force everything into a single line QFont f = p->font(); p->setFont(smallFont); QPen datePen = p->pen(); QColor dateColor = m_plainClockColor; dateColor.setAlphaF(0.7); datePen.setColor(dateColor); p->setPen(datePen); if (formFactor() == Plasma::Horizontal && (contentsRect.height() < smallFont.pointSize()*6)) { p->drawText(dateRect, Qt::TextSingleLine | Qt::AlignHCenter, m_dateString); } else { p->drawText(dateRect, Qt::TextWordWrap | Qt::AlignHCenter, m_dateString); } p->setFont(f); } if (m_useCustomColor || !m_svgExistsInTheme) { QFontMetrics fm(p->font()); QPointF timeTextOrigin(QPointF(qMax(0, (m_timeRect.center().x() - fm.width(fakeTimeString) / 2)), (m_timeRect.center().y() + fm.height() / 3))); p->translate(-0.5, -0.5); if (m_drawShadow) { QPen tmpPen = p->pen(); // Paint a backdrop behind the time's text qreal shadowOffset = 1.0; QPen shadowPen; QColor shadowColor = m_plainClockShadowColor; shadowColor.setAlphaF(.4); shadowPen.setColor(shadowColor); p->setPen(shadowPen); QPointF shadowTimeTextOrigin = QPointF(timeTextOrigin.x() + shadowOffset, timeTextOrigin.y() + shadowOffset); p->drawText(shadowTimeTextOrigin, timeString); p->setPen(tmpPen); // Paint the time itself with a linear translucency gradient QLinearGradient gradient = QLinearGradient(QPointF(0, 0), QPointF(0, fm.height())); QColor startColor = m_plainClockColor; startColor.setAlphaF(.95); QColor stopColor = m_plainClockColor; stopColor.setAlphaF(.7); gradient.setColorAt(0.0, startColor); gradient.setColorAt(0.5, stopColor); gradient.setColorAt(1.0, startColor); QBrush gradientBrush(gradient); QPen gradientPen(gradientBrush, tmpPen.width()); p->setPen(gradientPen); } p->drawText(timeTextOrigin, timeString); //when use the custom theme colors, draw the time textured } else { QRect adjustedTimeRect = m_pixmap.rect(); adjustedTimeRect.moveCenter(m_timeRect.center()); p->drawPixmap(adjustedTimeRect, m_pixmap); } }