[PC-BSD Commits] r17927 - pcbsd-projects/PCDM

svn at pcbsd.org svn at pcbsd.org
Tue Jul 24 17:18:09 PDT 2012


Author: kenmoore
Date: 2012-07-25 00:18:09 +0000 (Wed, 25 Jul 2012)
New Revision: 17927

Modified:
   pcbsd-projects/PCDM/PCDM.qrc
   pcbsd-projects/PCDM/fancySwitcher.cpp
   pcbsd-projects/PCDM/fancySwitcher.h
   pcbsd-projects/PCDM/pcdm-gui.cpp
Log:
Finish up the fancySwitcher widget, it now works properly with 1 item, still need to test multiple items



Modified: pcbsd-projects/PCDM/PCDM.qrc
===================================================================
--- pcbsd-projects/PCDM/PCDM.qrc	2012-07-24 20:42:27 UTC (rev 17926)
+++ pcbsd-projects/PCDM/PCDM.qrc	2012-07-25 00:18:09 UTC (rev 17927)
@@ -13,5 +13,9 @@
     <file>images/next.png</file>
     <file>images/info.png</file>
     <file>images/help.png</file>
+    <file>images/up.png</file>
+    <file>images/down.png</file>
+    <file>images/left.png</file>
+    <file>images/right.png</file>
   </qresource>
 </RCC>

Modified: pcbsd-projects/PCDM/fancySwitcher.cpp
===================================================================
--- pcbsd-projects/PCDM/fancySwitcher.cpp	2012-07-24 20:42:27 UTC (rev 17926)
+++ pcbsd-projects/PCDM/fancySwitcher.cpp	2012-07-25 00:18:09 UTC (rev 17927)
@@ -7,7 +7,7 @@
 FancySwitcher::FancySwitcher(QWidget* parent,bool horizontal) : QWidget(parent)
 {
   //Set the default values for the current item
-  idL.clear(); ttL.clear(); icL.clear();
+  idL.clear(); icL.clear();
   item=-1; oldItem=0; //default values for the current/old item number
   //Save whether it is a horizontal or vertical display
   isHorizontal = horizontal;
@@ -19,22 +19,29 @@
   pushForward = new QPushButton;
   pushBack = new QPushButton;
   iconViewer = new QGraphicsView();
-  pushForward->setIconSize(QSize(iconSize,iconSize));
-  pushBack->setIconSize(QSize(iconSize,iconSize));
+  iconViewer->setInteractive(FALSE);
+  iconViewer->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+  iconViewer->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+  pushForward->setIconSize(QSize(iconSize/2,iconSize/2));
+  pushBack->setIconSize(QSize(iconSize/2,iconSize/2));
   qDebug() << "Set the orientation and images";
   if(isHorizontal){
+    iconViewer->setFixedSize(2*iconSize,iconSize+2);
     pushBack->setIcon(QIcon(":images/left.png"));
     pushForward->setIcon(QIcon(":images/right.png"));
-    layout->addWidget(pushBack,0,0);
-    layout->addWidget(iconViewer,0,1);
-    layout->addWidget(pushForward,0,2);
+    layout->addWidget(pushBack,1,1);
+    layout->addWidget(iconViewer,1,2);
+    layout->addWidget(pushForward,1,3);
   }else{ //vertical
+    iconViewer->setFixedSize(iconSize+2,2*iconSize);
     pushBack->setIcon(QIcon(":images/up.png"));
     pushForward->setIcon(QIcon(":images/down.png"));
-    layout->addWidget(pushBack,0,0);
-    layout->addWidget(iconViewer,1,0);
-    layout->addWidget(pushForward,2,0);
+    layout->addWidget(pushBack,1,1);
+    layout->addWidget(iconViewer,2,1);
+    layout->addWidget(pushForward,3,1);
   }
+  //set this layout as the layout for the FancySwitcher
+  this->setLayout(layout);
   //connect the buttons to their appropriate slots
   connect(pushBack,SIGNAL(clicked()),this,SLOT(slotPushBack()));
   connect(pushForward,SIGNAL(clicked()),this,SLOT(slotPushForward()));
@@ -45,35 +52,36 @@
   checkButtons();
 }
 
+FancySwitcher::~FancySwitcher(){
+}
+
 void FancySwitcher::updateIconViewer(){
   //detect the base dimensions
-  int baseSize = iconSize * 1.5;
   int xsize,ysize;
   if(isHorizontal){
-    xsize = (2 + idL.length())*baseSize;
+    xsize = (idL.length()+1)*iconSize;
     ysize = iconSize;
   }else{ //vertical
     xsize = iconSize;
-    ysize = (2 + idL.length())*baseSize;
+    ysize = (idL.length()+1)*iconSize;
   }
-  qDebug() << "iconViewer dimensions:" << xsize << ysize;
+  qDebug() << "scene dimensions:" << xsize << ysize;
   //Create the scene with the proper dimensions
   scene = new QGraphicsScene(0,0,xsize,ysize);
   //Fill the scene with the given images
-  int offset = baseSize;
+  int offset = iconSize/2; //initial offset
   for(int i=0; i<idL.length(); i++){
     qDebug() << "offset" << offset;
     if(isHorizontal){
-      scene->addPixmap(QPixmap(icL[i]))->setOffset(offset,0);
+      icL[i]->setOffset(offset,0);
     }else{
-      scene->addPixmap(QPixmap(icL[i]))->setOffset(0,offset);
+      icL[i]->setOffset(0,offset);
     }
-    offset = offset + baseSize;
+    scene->addItem(icL[i]);
+    offset = offset + 5*iconSize/4; //have a 1/4 iconsize spacing between icons
   }
   //set the iconViewer to display the scene
-  qDebug() << "Setting the iconViewer scene";
-  if(item != -1){ iconViewer->setScene(scene); }
-  qDebug() << "Displaying Current Item";
+  iconViewer->setScene(scene);
   displayCurrentItem(FALSE);
 
 }
@@ -83,14 +91,12 @@
   //if( (item >= idL.length()) || (item < 0) ){item = oldItem; return;} //reset to the previous value and don't change the display
 
   if(item == -1){
-    qDebug() << "Center the view";
     iconViewer->centerOn(0,0);
-    qDebug() << "Show the iconviewer";
     iconViewer->show();
     return;
   }
   int baseSize = iconSize*1.5;
-  qDebug() << "baseSize:" << baseSize;
+  qDebug() << "iconSize:" << iconSize << "baseSize:" << baseSize;
   //Get the current/old display pixel
   int cPixel = baseSize + (oldItem*iconSize) + (oldItem*iconSize/2);
   //Get the new/desired display pixel
@@ -128,11 +134,7 @@
 
   }else{
     //Just center on the desired item (skip animation)
-    if(isHorizontal){
-      iconViewer->centerOn(tPixel,0);
-    }else{
-      iconViewer->centerOn(0,tPixel);
-    }
+    iconViewer->centerOn(icL[item]);
     iconViewer->show();
   }
 
@@ -142,14 +144,12 @@
 
 void FancySwitcher::checkButtons(){
   //Sanity check the current item value
-  qDebug() << "Check item limits";
   if(item > (idL.length()-1)){ item = idL.length()-1; }
-  if(item < 0){ item = 0; }
+  if(item < -1){ item = -1; }
   //Enable/Disable the pushbuttons as appropriate
-  qDebug() << "enable/disable the buttons";
   if(item == (idL.length()-1)){ pushForward->setEnabled(FALSE); }
   else{ pushForward->setEnabled(TRUE); }
-  if(item == 0){ pushBack->setEnabled(FALSE); }
+  if(item < 1){ pushBack->setEnabled(FALSE); }
   else{ pushBack->setEnabled(TRUE); };
 }
 
@@ -181,9 +181,13 @@
   }
   if(idL.indexOf(id)==-1){
     idL << id;
-    icL << icon;
-    ttL << tooltip;
+    icL << new QGraphicsPixmapItem(QPixmap(icon).scaled(iconSize,iconSize));
+    if(!tooltip.isEmpty()){
+      int index = idL.indexOf(id);
+      icL[index]->setToolTip(tooltip);
+    }
   }
+  if(item==-1){item = 0; qDebug() << "Changed to index=0";}
   updateIconViewer();
   checkButtons();
 }
@@ -203,11 +207,15 @@
     }else{
       if(idL.indexOf(idList[i].toLower()) == -1){
         idL << idList[i];
-        icL << iconList[i];
-        ttL << tooltipList[i];
+        icL << new QGraphicsPixmapItem(QPixmap(iconList[i]).scaled(iconSize,iconSize));
+	if(!tooltipList[i].isEmpty()){
+          int index = idL.indexOf(idList[i]);
+          icL[index]->setToolTip(tooltipList[i]);
+	}
       }
     }
   }
+  if(item==-1){item=0;}
   updateIconViewer();
   checkButtons();
 }
@@ -220,7 +228,6 @@
   }else{
     idL.removeAt(index);
     icL.removeAt(index);
-    ttL.removeAt(index);
   }
   updateIconViewer();
   checkButtons();
@@ -235,7 +242,6 @@
     }else{
       idL.removeAt(index);
       icL.removeAt(index);
-      ttL.removeAt(index);
     }
   }
   updateIconViewer();
@@ -261,9 +267,14 @@
 void FancySwitcher::setIconSize(int xysize){
   iconSize = xysize; //change the saved icon size
   //Update the pushbuttons icons
-  pushBack->setIconSize(QSize(iconSize,iconSize));
-  pushForward->setIconSize(QSize(iconSize,iconSize));
+  pushBack->setIconSize(QSize(iconSize/2,iconSize/2));
+  pushForward->setIconSize(QSize(iconSize/2,iconSize/2));
   //Update the iconViewer sizes
+  if(isHorizontal){
+    iconViewer->setFixedSize(2*iconSize,iconSize+2);
+  }else{
+    iconViewer->setFixedSize(iconSize+2,2*iconSize);
+  }
   updateIconViewer();
 }
 

Modified: pcbsd-projects/PCDM/fancySwitcher.h
===================================================================
--- pcbsd-projects/PCDM/fancySwitcher.h	2012-07-24 20:42:27 UTC (rev 17926)
+++ pcbsd-projects/PCDM/fancySwitcher.h	2012-07-25 00:18:09 UTC (rev 17927)
@@ -12,6 +12,7 @@
 #include <QGraphicsView>
 #include <QGraphicsScene>
 #include <QGraphicsPixmapItem>
+#include <QGraphicsItem>
 #include <QGridLayout>
 #include <QPixmap>
 #include <QDebug>
@@ -22,7 +23,8 @@
 
   public:
 	FancySwitcher(QWidget* parent = 0, bool horizontal = TRUE);
-
+	~FancySwitcher();
+	
 	void addItem(QString, QString, QString tooltip = "");
 	void addItems(QStringList, QStringList, QStringList);
 	void removeItem(QString);
@@ -38,8 +40,7 @@
 	QGraphicsView* iconViewer;
 	QGraphicsScene* scene;
 	QStringList idL;
-	QStringList ttL;
-	QStringList icL;
+	QList<QGraphicsPixmapItem*> icL;
 	int item, oldItem;
 	bool isHorizontal;
 	int iconSize;

Modified: pcbsd-projects/PCDM/pcdm-gui.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.cpp	2012-07-24 20:42:27 UTC (rev 17926)
+++ pcbsd-projects/PCDM/pcdm-gui.cpp	2012-07-25 00:18:09 UTC (rev 17927)
@@ -165,40 +165,23 @@
                       Theme::objectLocationColumnSpan("login"), Qt::AlignCenter); 
 
     //----Desktop Environment Switcher
-      //NOTE: This will be changed to a "fancy" switcher later)
-    QString deLayout = Theme::objectIconStyle("desktop");
+    //Get the available DE's
+    QStringList deList = Backend::getAvailableDesktops();
+    //Create the switcher
     FancySwitcher* deSwitcher = new FancySwitcher(this);
-   // QComboBox* deSwitcher = new QComboBox;
-   QStringList deList = Backend::getAvailableDesktops();
+    deSwitcher->setIconSize(64);
+    //deSwitcher->setStyleSheet(Theme::objectStyleSheet("desktop"));
+    //Add the available desktops to the switcher
     qDebug() << "At setup for deSwitcher";
-    deSwitcher->addItem("kde","/home/kenmoore/Downloads/kde.png","");
-    //deSwitcher->setCurrentIndex(0); //select the first desktop on the list (for now)
-    //deSwitcher->setStyleSheet(Theme::objectStyleSheet("desktop"));
-    //if(deLayout == "disabled"){
-      //Icon Disabled - just add widget to the grid
-      grid->addWidget( deSwitcher, Theme::objectLocationRow("desktop"), \
+    deSwitcher->addItem("kde","/home/kenmoore/Downloads/kde.png","KDE desktop environment");
+    //Set the switcher to the last used desktop environment
+    //deSwitcher->setCurrentItem(deList[index]); 
+    grid->addWidget( deSwitcher, Theme::objectLocationRow("desktop"), \
                       Theme::objectLocationColumn("desktop"), \
                       Theme::objectLocationRowSpan("desktop"), \
                       Theme::objectLocationColumnSpan("desktop"), Qt::AlignCenter); 
-    /*}else{
-      //Put the Icon and Widget in their own layout before adding to the main grid
-      int rI,rW,cI,cW;
-      if(deLayout=="above"){ rI=0; cI=0; rW=1; cW=0; } //icon above
-      if(deLayout=="below"){ rI=1; cI=0; rW=0; cW=0; } //icon below
-      if(deLayout=="left") { rI=0; cI=0; rW=0; cW=1; } //icon to the left
-      if(deLayout=="right"){ rI=0; cI=1; rW=0; cW=0; } //icon to the right
-      QGridLayout* degrid = new QGridLayout;
-      QPixmap tmp( Theme::objectIconPath("desktop") );
-      QLabel* deIcon = new QLabel; deIcon->setPixmap(tmp.scaled(Theme::objectIconSize("desktop")));
-      degrid->addWidget(deSwitcher,rW,cW,Qt::AlignCenter);
-      degrid->addWidget(deIcon,rI,cI,Qt::AlignCenter);
 
-      grid->addLayout( degrid, Theme::objectLocationRow("desktop"), \
-                      Theme::objectLocationColumn("desktop"), \
-                      Theme::objectLocationRowSpan("desktop"), \
-                      Theme::objectLocationColumnSpan("desktop"), Qt::AlignCenter);
-    }
-*/    //----WINDOW SPACERS
+    //----WINDOW SPACERS
     QStringList spacers = Theme::getSpacers();
     for(int i=0; i<spacers.length(); i++){
       QString type = spacers[i].section("::",0,0);



More information about the Commits mailing list