From kde-commits Fri Mar 14 20:18:56 2008 From: Anne-Marie Mahfouf Date: Fri, 14 Mar 2008 20:18:56 +0000 To: kde-commits Subject: KDE/kdebase/workspace/plasma/applets/pager Message-Id: <1205525936.433806.422.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120552598704669 SVN commit 785734 by annma: patch from Rafał Miłecki as proposed on mailing list and approved by Aaron and Jeremy - thanks for your contribution :) M +55 -21 pager.cpp M +10 -2 pager.h M +8 -14 pagerConfig.ui --- trunk/KDE/kdebase/workspace/plasma/applets/pager/pager.cpp #785733:785734 @@ -47,7 +47,7 @@ Pager::Pager(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args), m_dialog(0), - m_showDesktopNumber(true), + m_displayedText(Number), m_showWindowIcons(true), m_rows(2), m_columns(0), @@ -68,7 +68,7 @@ createMenu(); KConfigGroup cg = config(); - m_showDesktopNumber = cg.readEntry("showDesktopNumber", m_showDesktopNumber); + m_displayedText = (DisplayedText)cg.readEntry("displayedText", (int)m_displayedText); m_showWindowIcons = cg.readEntry("showWindowIcons", m_showWindowIcons); m_rows = globalConfig().readEntry("rows", m_rows); @@ -89,6 +89,7 @@ connect(KWindowSystem::self(), SIGNAL(windowRemoved(WId)), this, SLOT(windowRemoved(WId))); connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)), this, SLOT(activeWindowChanged(WId))); connect(KWindowSystem::self(), SIGNAL(numberOfDesktopsChanged(int)), this, SLOT(numberOfDesktopsChanged(int))); + connect(KWindowSystem::self(), SIGNAL(desktopNamesChanged()), this, SLOT(desktopNamesChanged())); connect(KWindowSystem::self(), SIGNAL(stackingOrderChanged()), this, SLOT(stackingOrderChanged())); connect(KWindowSystem::self(), SIGNAL(windowChanged(WId,unsigned int)), this, SLOT(windowChanged(WId,unsigned int))); connect(KWindowSystem::self(), SIGNAL(showingDesktopChanged(bool)), this, SLOT(showingDesktopChanged(bool))); @@ -162,7 +163,12 @@ connect( m_dialog, SIGNAL(okClicked()), this, SLOT(configAccepted()) ); } - ui.showDesktopNumberCheckBox->setChecked(m_showDesktopNumber); + ui.displayedTextComboBox->clear(); + ui.displayedTextComboBox->addItem(i18n("Desktop number")); + ui.displayedTextComboBox->addItem(i18n("Desktop name")); + ui.displayedTextComboBox->addItem(i18n("None")); + ui.displayedTextComboBox->setCurrentIndex((int)m_displayedText); + ui.showWindowIconsCheckBox->setChecked(m_showWindowIcons); ui.spinRows->setValue(m_rows); @@ -177,20 +183,34 @@ return; } - const int padding = 2; + const int padding = 2; // Space between miniatures of desktops + const int textMargin = 3; // Space between name of desktop and border int columns = m_desktopCount / m_rows + m_desktopCount % m_rows; qreal itemHeight; qreal itemWidth; - if (formFactor() == Plasma::Vertical) { + if (formFactor() == Plasma::Vertical) { // Panel is on left or right itemWidth = (contentSize().width() - padding * (columns - 1)) / columns; - m_scaleFactor = itemWidth / QApplication::desktop()->width(); - itemHeight = QApplication::desktop()->height() * m_scaleFactor; - } else { + m_widthScaleFactor = itemWidth / QApplication::desktop()->width(); + itemHeight = QApplication::desktop()->height() * m_widthScaleFactor; + m_heightScaleFactor = m_widthScaleFactor; + } else { // Panel is on top or bottom itemHeight = (contentSize().height() - padding * (m_rows - 1)) / m_rows; - m_scaleFactor = itemHeight / QApplication::desktop()->height(); - itemWidth = QApplication::desktop()->width() * m_scaleFactor; + m_heightScaleFactor = itemHeight / QApplication::desktop()->height(); + itemWidth = QApplication::desktop()->width() * m_heightScaleFactor; + if (m_displayedText==Name) { + // When panel is in this position we are not limited by low width and we can + // afford increasing width of applet to be able to display every name of desktops + for (int i = 0; i < m_desktopCount; i++) { + QFontMetricsF metrics(KGlobalSettings::taskbarFont()); + QSizeF textSize = metrics.size(Qt::TextSingleLine, KWindowSystem::desktopName(i+1)); + if (textSize.width() + textMargin * 2 > itemWidth) { + itemWidth = textSize.width() + textMargin * 2; + } + } + } + m_widthScaleFactor = itemWidth / QApplication::desktop()->width(); } m_rects.clear(); @@ -249,10 +269,10 @@ QRect windowRect = info.frameGeometry(); if( KWindowSystem::mapViewport()) windowRect = fixViewportPosition( windowRect ); - windowRect = QRectF(windowRect.x() * m_scaleFactor, - windowRect.y() * m_scaleFactor, - windowRect.width() * m_scaleFactor, - windowRect.height() * m_scaleFactor).toRect(); + windowRect = QRectF(windowRect.x() * m_widthScaleFactor, + windowRect.y() * m_heightScaleFactor, + windowRect.width() * m_widthScaleFactor, + windowRect.height() * m_heightScaleFactor).toRect(); windowRect.translate(m_rects[i].topLeft().toPoint()); m_windowRects[i].append(QPair(window, windowRect)); if (window == KWindowSystem::activeWindow()) { @@ -268,9 +288,9 @@ KConfigGroup cg = config(); bool changed = false; - if (m_showDesktopNumber != ui.showDesktopNumberCheckBox->isChecked()) { - m_showDesktopNumber = ui.showDesktopNumberCheckBox->isChecked(); - cg.writeEntry("showDesktopNumber", m_showDesktopNumber); + if ((int)m_displayedText != ui.displayedTextComboBox->currentIndex()) { + m_displayedText = (DisplayedText)ui.displayedTextComboBox->currentIndex(); + cg.writeEntry("displayedText", (int)m_displayedText); changed = true; } @@ -354,6 +374,16 @@ } } +void Pager::desktopNamesChanged() +{ + m_rects.clear(); + recalculateGeometry(); + + if (!m_timer->isActive()) { + m_timer->start(WINDOW_UPDATE_DELAY); + } +} + void Pager::stackingOrderChanged() { if (!m_timer->isActive()) { @@ -470,7 +500,7 @@ if (m_dragId > 0) { if (m_dragHighlightedDesktop != -1) { QPointF dest = m_dragCurrentPos - m_rects[m_dragHighlightedDesktop].topLeft() - m_dragOriginalPos + m_dragOriginal.topLeft(); - dest = QPointF(dest.x()/m_scaleFactor, dest.y()/m_scaleFactor); + dest = QPointF(dest.x()/m_widthScaleFactor, dest.y()/m_heightScaleFactor); if( !KWindowSystem::mapViewport()) { KWindowSystem::setOnDesktop(m_dragId, m_dragHighlightedDesktop+1); // use _NET_MOVERESIZE_WINDOW rather than plain move, so that the WM knows this is a pager request @@ -583,6 +613,7 @@ drawingColor.setAlpha(238); QBrush activeWindowBrush(drawingColor); + // Draw backgrounds of desktops painter->setPen(Qt::NoPen); for (int i = 0; i < m_desktopCount; i++) { if (m_rects[i] == m_hoverRect) { @@ -593,8 +624,8 @@ painter->drawRect(m_rects[i]); } + // Draw miniatures of windows from each desktop painter->setPen(windowPen); - for (int i = 0; i < m_windowRects.count(); i++) { for (int j = 0; j < m_windowRects[i].count(); j++) { QRect rect = m_windowRects[i][j].second; @@ -619,7 +650,7 @@ } } - // draw desktop frame and number + // Draw desktop frame and possibly text over it painter->setClipRect(option->exposedRect); QPen activePen(Plasma::Theme::self()->textColor()); QPen drawingPen = QPen(); @@ -634,9 +665,12 @@ painter->setPen(drawingPen); painter->drawRect(m_rects[i]); - if (m_showDesktopNumber) { + if (m_displayedText==Number) { // Display number of desktop painter->setPen(activePen); painter->drawText(m_rects[i], Qt::AlignCenter, QString::number(i+1)); + } else if (m_displayedText==Name) { // Display name of desktop + painter->setPen(activePen); + painter->drawText(m_rects[i], Qt::AlignCenter, KWindowSystem::desktopName(i+1)); } } } --- trunk/KDE/kdebase/workspace/plasma/applets/pager/pager.h #785733:785734 @@ -67,6 +67,7 @@ void windowRemoved(WId id); void activeWindowChanged(WId id); void numberOfDesktopsChanged(int num); + void desktopNamesChanged(); void stackingOrderChanged(); void windowChanged(WId id, unsigned int properties); void showingDesktopChanged(bool showing); @@ -80,14 +81,21 @@ QTimer* m_timer; KDialog *m_dialog; Ui::pagerConfig ui; - bool m_showDesktopNumber; + enum DisplayedText + { + Number, + Name, + None + }; + DisplayedText m_displayedText; bool m_showWindowIcons; int m_rows; int m_columns; int m_desktopCount; int m_currentDesktop; - qreal m_scaleFactor; + qreal m_widthScaleFactor; + qreal m_heightScaleFactor; QSizeF m_size; QList m_rects; QRectF m_hoverRect; --- trunk/KDE/kdebase/workspace/plasma/applets/pager/pagerConfig.ui #785733:785734 @@ -5,7 +5,7 @@ 0 0 - 199 + 250 52 @@ -16,25 +16,19 @@ Configure Pager - + 0 - - 0 - - - 0 - - - 0 - - - + + - Display the desktop &number + Displayed text + + +