[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/applets/pager
From:       Anne-Marie Mahfouf <annma () kde ! org>
Date:       2008-03-14 20:18:56
Message-ID: 1205525936.433806.422.nullmailer () svn ! kde ! org
[Download RAW message or body]

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<WId, QRect>(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<QRectF> m_rects;
 	QRectF m_hoverRect;
--- trunk/KDE/kdebase/workspace/plasma/applets/pager/pagerConfig.ui #785733:785734
@@ -5,7 +5,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>199</width>
+    <width>250</width>
     <height>52</height>
    </rect>
   </property>
@@ -16,25 +16,19 @@
    <string>Configure Pager</string>
   </property>
   <layout class="QGridLayout" >
-   <property name="leftMargin" >
+   <property name="margin" >
     <number>0</number>
    </property>
-   <property name="topMargin" >
-    <number>0</number>
-   </property>
-   <property name="rightMargin" >
-    <number>0</number>
-   </property>
-   <property name="bottomMargin" >
-    <number>0</number>
-   </property>
-   <item row="0" column="0" colspan="3" >
-    <widget class="QCheckBox" name="showDesktopNumberCheckBox" >
+   <item row="0" column="0" >
+    <widget class="QLabel" name="labelText" >
      <property name="text" >
-      <string>Display the desktop &amp;number</string>
+      <string>Displayed text</string>
      </property>
     </widget>
    </item>
+   <item row="0" column="1" colspan="2" >
+    <widget class="QComboBox" name="displayedTextComboBox" />
+   </item>
    <item row="1" column="0" colspan="3" >
     <widget class="QCheckBox" name="showWindowIconsCheckBox" >
      <property name="text" >


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic