[PC-BSD Commits] r17887 - pcbsd-projects/PCDM
svn at pcbsd.org
svn at pcbsd.org
Mon Jul 23 16:20:45 PDT 2012
Author: kenmoore
Date: 2012-07-23 23:20:45 +0000 (Mon, 23 Jul 2012)
New Revision: 17887
Modified:
pcbsd-projects/PCDM/PCDM.pro
pcbsd-projects/PCDM/fancySwitcher.cpp
pcbsd-projects/PCDM/fancySwitcher.h
pcbsd-projects/PCDM/pcdm-gui.cpp
pcbsd-projects/PCDM/pcdm-gui.h
Log:
Almost finish up the FancySwitcher class, it just needs a bit more work to get it working properly.
Modified: pcbsd-projects/PCDM/PCDM.pro
===================================================================
--- pcbsd-projects/PCDM/PCDM.pro 2012-07-23 19:16:15 UTC (rev 17886)
+++ pcbsd-projects/PCDM/PCDM.pro 2012-07-23 23:20:45 UTC (rev 17887)
@@ -7,12 +7,14 @@
pcdm-gui.cpp \
pcdm-backend.cpp \
pcdm-themes.cpp \
- pcdm-config.cpp
+ pcdm-config.cpp \
+ fancySwitcher.cpp
HEADERS += pcdm-gui.h \
pcdm-backend.h \
pcdm-themes.h \
- pcdm-config.h
+ pcdm-config.h \
+ fancySwitcher.h
TRANSLATIONS = i18n/PCDM_af.ts \
i18n/PCDM_ar.ts \
Modified: pcbsd-projects/PCDM/fancySwitcher.cpp
===================================================================
--- pcbsd-projects/PCDM/fancySwitcher.cpp 2012-07-23 19:16:15 UTC (rev 17886)
+++ pcbsd-projects/PCDM/fancySwitcher.cpp 2012-07-23 23:20:45 UTC (rev 17887)
@@ -4,32 +4,35 @@
#include "fancySwitcher.h"
-FancySwitcher::FancySwitcher(QWidget* parent,bool horizontal) : QWidget(parent)
+FancySwitcher::FancySwitcher(QWidget* parent,bool horizontal) : QWidget(parent)
{
+ //Set the default values for the current item
+ idL.clear(); ttL.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;
//Set the default size for the images
iconSize = 32; //default all icons in the viewer to 32x32 (can be changed later)
//Create the Grid layout
- layout = new QGridLayout();
+ QGridLayout* layout = new QGridLayout();
//Add the buttons to the grid (back is always left/up)
- pushForward = new QPushButton();
- pushBack = new QPushButton();
- iconViewer = new QGraphicsView();
+ QPushButton* pushForward = new QPushButton;
+ QPushButton* pushBack = new QPushButton;
+ QGraphicsView* iconViewer = new QGraphicsView();
pushForward->setIconSize(QSize(iconSize,iconSize));
pushBack->setIconSize(QSize(iconSize,iconSize));
if(isHorizontal){
- pushBack->setIcon(":images/left.png");
- pushForward->setIcon(":images/right.png");
+ pushBack->setIcon(QIcon(":images/left.png"));
+ pushForward->setIcon(QIcon(":images/right.png"));
layout->addWidget(pushBack,0,0);
layout->addWidget(iconViewer,0,1);
- layout->addWidget(pushnext,0,2);
+ layout->addWidget(pushForward,0,2);
}else{ //vertical
- pushBack->setIcon(":images/up.png");
- pushForward->setIcon(":images/down.png");
+ pushBack->setIcon(QIcon(":images/up.png"));
+ pushForward->setIcon(QIcon(":images/down.png"));
layout->addWidget(pushBack,0,0);
layout->addWidget(iconViewer,1,0);
- layout->addWidget(pushnext,2,0);
+ layout->addWidget(pushForward,2,0);
}
//connect the buttons to their appropriate slots
connect(pushBack,SIGNAL(clicked()),this,SLOT(slotPushBack()));
@@ -52,11 +55,13 @@
xsize = iconSize;
ysize = (2 + idL.length())*baseSize;
}
+ qDebug() << "iconViewer 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;
for(int i=0; i<idL.length(); i++){
+ qDebug() << "offset" << offset;
if(isHorizontal){
scene->addPixmap(QPixmap(icL[i]))->setOffset(offset,0);
}else{
@@ -65,17 +70,26 @@
offset = offset + baseSize;
}
//set the iconViewer to display the scene
- item=0; olditem=0; //default values for the current/old item number
- iconViewer->setScene(scene);
+ qDebug() << "Setting the iconViewer scene";
+ if(item != -1){ iconViewer->setScene(scene); }
+ qDebug() << "Displaying Current Item";
displayCurrentItem(FALSE);
}
void FancySwitcher::displayCurrentItem(bool showAnimation){
//Check that the new item is valid
- if( (item >= idL.length()) || (item < 0) ){item = oldItem; return;} //reset to the previous value and don't change the display
+ //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;
//Get the current/old display pixel
int cPixel = baseSize + (oldItem*iconSize) + (oldItem*iconSize/2);
//Get the new/desired display pixel
@@ -84,7 +98,7 @@
bool moveForward = TRUE;
if(tPixel < cPixel){ moveForward = FALSE; }
if(tPixel == cPixel){ showAnimation = FALSE; } //same item, skip the animation loop and just refresh
-
+ qDebug() << "displayItem:" << item << oldItem << cPixel << tPixel << moveForward;
//Show the scrolling animation if desired
if(showAnimation){
if(moveForward){
@@ -126,7 +140,11 @@
}
void FancySwitcher::checkButtons(){
- if(item == (idL.length-1)){ pushForward->setEnabled(FALSE); }
+ //Sanity check the current item value
+ if(item > (idL.length()-1)){ item = idL.length()-1; }
+ if(item < 0){ item = 0; }
+ //Enable/Disable the pushbuttons as appropriate
+ if(item == (idL.length()-1)){ pushForward->setEnabled(FALSE); }
else{ pushForward->setEnabled(TRUE); }
if(item == 0){ pushBack->setEnabled(FALSE); }
else{ pushBack->setEnabled(TRUE); };
@@ -137,6 +155,8 @@
if(item < 0){ item = 0; } //cannot go lower than the first item
displayCurrentItem(TRUE); //show animation of changing items
checkButtons();
+ emit itemChanged();
+ emit itemChanged(idL[item]);
}
void FancySwitcher::slotPushForward(){
@@ -144,25 +164,79 @@
if(item >= idL.length()){ item = idL.length()-1; } //cannot go higher than the last item
displayCurrentItem(TRUE);
checkButtons();
+ emit itemChanged();
+ emit itemChanged(idL[item]);
}
//-----------------------------
// PUBLIC FUNCTIONS
//-----------------------------
-void FancySwitcher::addItem(QString id, QString icon, QString tooltip = ""){
-
+void FancySwitcher::addItem(QString id, QString icon, QString tooltip){
+ if(!QFile::exists(icon)){
+ qDebug() << "FancySwitcher: invalid icon file" << icon;
+ return;
+ }
+ if(idL.indexOf(id)==-1){
+ idL << id;
+ icL << icon;
+ ttL << tooltip;
+ }
+ updateIconViewer();
+ checkButtons();
}
void FancySwitcher::addItems(QStringList idList, QStringList iconList, QStringList tooltipList){
+ //Check that all the lists are the same length
+ if(!( idList.length()==iconList.length() && idList.length()==tooltipList.length() )){
+ qDebug() << "FancySwitcher: item lists are not equal length";
+ return;
+ }
+ //Check each item and add it to the list if applicable
+ for(int i=0; i<idList.length(); i++){
+ if(!QFile::exists(iconList[i])){
+ qDebug() << "FancySwitcher: invalid icon file" << iconList[i];
+ return;
+ }else{
+ if(idL.indexOf(idList[i].toLower()) == -1){
+ idL << idList[i];
+ icL << iconList[i];
+ ttL << tooltipList[i];
+ }
+ }
+ }
+ updateIconViewer();
+ checkButtons();
}
void FancySwitcher::removeItem(QString id){
-
+ int index = idL.indexOf(id.toLower());
+ if(index == -1){
+ qDebug() << "FancySwitcher: Item does not exist -" <<id;
+ return;
+ }else{
+ idL.removeAt(index);
+ icL.removeAt(index);
+ ttL.removeAt(index);
+ }
+ updateIconViewer();
+ checkButtons();
}
void FancySwitcher::removeItems(QStringList idList){
-
+ for(int i=0; i<idList.length(); i++){
+ int index = idL.indexOf(idList[i].toLower());
+ if(index == -1){
+ qDebug() << "FancySwitcher: Item does not exist -" <<idList[i];
+ return;
+ }else{
+ idL.removeAt(index);
+ icL.removeAt(index);
+ ttL.removeAt(index);
+ }
+ }
+ updateIconViewer();
+ checkButtons();
}
QString FancySwitcher::currentItem(){
@@ -170,7 +244,15 @@
}
void FancySwitcher::setCurrentItem(QString id){
-
+ int index = idL.indexOf(id.toLower());
+ if(index == -1){
+ qDebug() << "FancySwitcher: Item does not exist -" << id;
+ return;
+ }else{
+ item = index;
+ displayCurrentItem(FALSE); //do not show animation
+ checkButtons();
+ }
}
void FancySwitcher::setIconSize(int xysize){
Modified: pcbsd-projects/PCDM/fancySwitcher.h
===================================================================
--- pcbsd-projects/PCDM/fancySwitcher.h 2012-07-23 19:16:15 UTC (rev 17886)
+++ pcbsd-projects/PCDM/fancySwitcher.h 2012-07-23 23:20:45 UTC (rev 17887)
@@ -6,6 +6,14 @@
#define FANCY_SWITCHER_H
#include <QWidget>
+#include <QFile>
+#include <QCoreApplication>
+#include <QPushButton>
+#include <QGraphicsView>
+#include <QGraphicsScene>
+#include <QGraphicsPixmapItem>
+#include <QGridLayout>
+#include <QPixmap>
#include <QDebug>
class FancySwitcher : public QWidget
@@ -25,9 +33,10 @@
void changeButtonIcon(QString, QString);
private:
- QPushButton* pushBack, pushForward;
+ QPushButton* pushBack;
+ QPushButton* pushForward;
QGraphicsView* iconViewer;
- QGraphicScene* scene;
+ QGraphicsScene* scene;
QStringList idL,ttL,icL;
int item, oldItem;
bool isHorizontal;
@@ -41,9 +50,9 @@
void slotPushBack();
void slotPushForward();
- public signals:
- itemChanged();
- itemChanged(QString);
+ signals:
+ void itemChanged();
+ void itemChanged(QString);
};
#endif
Modified: pcbsd-projects/PCDM/pcdm-gui.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.cpp 2012-07-23 19:16:15 UTC (rev 17886)
+++ pcbsd-projects/PCDM/pcdm-gui.cpp 2012-07-23 23:20:45 UTC (rev 17887)
@@ -166,17 +166,20 @@
//----Desktop Environment Switcher
//NOTE: This will be changed to a "fancy" switcher later)
QString deLayout = Theme::objectIconStyle("desktop");
- QComboBox* deSwitcher = new QComboBox;
- deSwitcher->addItems(Backend::getAvailableDesktops());
- deSwitcher->setCurrentIndex(0); //select the first desktop on the list (for now)
- deSwitcher->setStyleSheet(Theme::objectStyleSheet("desktop"));
- if(deLayout == "disabled"){
+ FancySwitcher* deSwitcher = new FancySwitcher;
+ // QComboBox* deSwitcher = new QComboBox;
+ QStringList deList = Backend::getAvailableDesktops();
+ 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"), \
Theme::objectLocationColumn("desktop"), \
Theme::objectLocationRowSpan("desktop"), \
Theme::objectLocationColumnSpan("desktop"), Qt::AlignCenter);
- }else{
+ /*}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
@@ -194,7 +197,7 @@
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);
Modified: pcbsd-projects/PCDM/pcdm-gui.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.h 2012-07-23 19:16:15 UTC (rev 17886)
+++ pcbsd-projects/PCDM/pcdm-gui.h 2012-07-23 23:20:45 UTC (rev 17887)
@@ -19,6 +19,7 @@
#include "pcdm-backend.h"
#include "pcdm-themes.h"
+#include "fancySwitcher.h"
class PCDMgui : public QMainWindow
{
@@ -43,7 +44,8 @@
//Objects
QToolBar* toolbar;
QMenu* systemMenu;
- QComboBox* unameline,deSwitcher;
+ QComboBox* unameline;//,deSwitcher;
+ FancySwitcher* deSwitcher;
QLineEdit* pwline;
QX11EmbedContainer* container;
QProcess* vkbd;
More information about the Commits
mailing list