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

svn at pcbsd.org svn at pcbsd.org
Thu Jan 31 09:53:00 PST 2013


Author: kenmoore
Date: 2013-01-31 17:53:00 +0000 (Thu, 31 Jan 2013)
New Revision: 21265

Modified:
   pcbsd-projects/PCDM/loginWidget.cpp
   pcbsd-projects/PCDM/loginWidget.h
Log:
Large visual update to the login widget for PCDM. Now to test it...



Modified: pcbsd-projects/PCDM/loginWidget.cpp
===================================================================
--- pcbsd-projects/PCDM/loginWidget.cpp	2013-01-31 17:49:51 UTC (rev 21264)
+++ pcbsd-projects/PCDM/loginWidget.cpp	2013-01-31 17:53:00 UTC (rev 21265)
@@ -4,7 +4,7 @@
 
 #include "loginWidget.h"
 
-LoginWidget::LoginWidget(QWidget* parent) : QWidget(parent)
+LoginWidget::LoginWidget(QWidget* parent) : QGroupBox(parent)
 {
   //Set the default values for the current item
   idL.clear(); //Clear the login names available
@@ -13,7 +13,8 @@
   
   //Create the Grid layout
   QGridLayout* layout = new QGridLayout();
-  QHBoxLayout* hlayout = new QHBoxLayout();
+  QHBoxLayout* hlayout1 = new QHBoxLayout();
+  QHBoxLayout* hlayout2 = new QHBoxLayout();
   QVBoxLayout* vlayout = new QVBoxLayout();
   //Create the items
   listUsers = new QComboBox;
@@ -24,18 +25,21 @@
   pushViewPassword = new QToolButton;
 	QAction* tmp2 = new QAction(this);
 	pushViewPassword->setDefaultAction( tmp2 );
-  displayIcon = new QLabel;
+  pushUserIcon = new QToolButton;
+	QAction* tmp3 = new QAction(this);
+	pushUserIcon->setDefaultAction( tmp3 );
   //Add the items to the grid
-  layout->addWidget(displayIcon,0,0);
-    vlayout->addWidget(listUsers);
-      hlayout->addWidget(linePassword);
-      hlayout->addWidget(pushViewPassword);
-    vlayout->addLayout(hlayout);
-  layout->addLayout(vlayout,0,1);
-  layout->addWidget(pushLogin,0,2);
+      hlayout1->addWidget(pushUserIcon);
+      hlayout1->addWidget(listUsers);
+    vlayout->addLayout(hlayout1);
+      hlayout2->addWidget(linePassword);
+      hlayout2->addWidget(pushViewPassword);
+    vlayout->addLayout(hlayout2);
+  layout->addLayout(vlayout,0,0);
+  layout->addWidget(pushLogin,0,1);
   //Setup the Signals/Slots
   connect(pushLogin,SIGNAL(clicked()),this,SLOT(slotTryLogin()));
-  //connect(pushViewPassword,SIGNAL(clicked()),this,SLOT(slotChangePWView()));
+  connect(pushUserIcon,SIGNAL(triggered()), this, SLOT(slotUserActivated()));
   connect(pushViewPassword,SIGNAL(pressed()),this,SLOT(slotChangePWView()));
   connect(pushViewPassword,SIGNAL(released()),this,SLOT(slotChangePWView()));
   connect(listUsers,SIGNAL(activated(int)),this,SLOT(slotChooseUser(int)));
@@ -67,7 +71,7 @@
   }else{
     linePassword->setEchoMode(QLineEdit::Password);  	  
   }
-
+  retranslateUi();
 }
 
 void LoginWidget::keyPressEvent(QKeyEvent *e){
@@ -79,15 +83,25 @@
     }
   }else if(e->key() == Qt::Key_Escape){
     if(userSelected){
-      userSelected = FALSE;
-      updateWidget();
-      listUsers->setFocus();
+      slotUserUnselected();
     }else{
       emit escapePressed();
     }
   }
 }
 
+//-------------------------------------
+//    PRIVATE SLOTS
+//-------------------------------------
+void LoginWidget::slotUserActivated(){
+    //Toggle the user box as to what is visible
+    if(!userSelected){ 
+	slotUserSelected(); 
+    }else{
+	slotUserUnselected();
+    }
+}
+
 void LoginWidget::slotTryLogin(){
   QString user = listUsers->currentText();
   QString pw = linePassword->text();
@@ -97,13 +111,23 @@
 void LoginWidget::slotChooseUser(int i){
   if(i!=-1){ slotUserSelected(); }	
 }
+
 void LoginWidget::slotUserSelected(){
   userSelected = TRUE;
   pwVisible = FALSE;
+  linePassword->clear(); //make sure the password is cleared if the user is changed
   updateWidget();
   linePassword->setFocus(); 
 }
 
+void LoginWidget::slotUserUnselected(){
+  userSelected = FALSE;
+  pwVisible = FALSE;
+  linePassword->clear(); //make sure the password is cleared if the user is changed
+  updateWidget();
+  listUsers->setFocus();
+}
+
 void LoginWidget::slotChangePWView(){
   if(pwVisible){
     pwVisible = FALSE;
@@ -112,6 +136,7 @@
   }
   updateWidget();
 }
+
 //-----------------------------
 //     PUBLIC FUNCTIONS
 //-----------------------------
@@ -143,16 +168,21 @@
   listUsers->setCurrentIndex(0);
 }
 
+void LoginWidget::displayHostName(QString name){
+  hostName = name;
+  retranslateUi();
+}
+
 void LoginWidget::setIconSize(int xysize){
   //Update the pushbuttons icons
-  displayIcon->resize(QSize(xysize,xysize));
+  pushUserIcon->resize(QSize(xysize,xysize));
   pushLogin->setIconSize(QSize(xysize,xysize));
 
 }
 
 void LoginWidget::changeButtonIcon(QString button, QString iconFile){
   if(!QFile::exists(iconFile)){ qDebug() << "LoginWidget: invalid image file"<<iconFile; return; }
-  if(button.toLower() == "display"){ displayIcon->setPixmap(QPixmap(iconFile)); }
+  if(button.toLower() == "display"){ pushUserIcon->defaultAction()->setIcon(QIcon(iconFile)); }
   else if(button.toLower() == "login"){ pushLogin->defaultAction()->setIcon(QIcon(iconFile)); }
   else if(button.toLower() == "pwview"){ pushViewPassword->defaultAction()->setIcon(QIcon(iconFile)); }
   else{ 
@@ -170,3 +200,44 @@
     qDebug() << "LoginWidget: Invalid item to change style" << item << " - valid items are \"login\", \"pwview\", \"user\", and \"password\"";	
   }
 }
+
+void LoginWidget::setBackgroundFade(bool verticalFade, int percentfade, QString colorTL, QString colorBR){
+  //Set the background fade for the widget
+  QString style = "QGroupBox {background-color: qlineargradient(x1: 0, y1: 0, x2: %h, y2: %v, stop: 0 %c1, stop 1: %c2) }";
+  if(percentfade >100){ percentfade = 100; }
+  if(percentfade < 0){percentfade = 0; }
+  double fade = percentfade/10.0;
+  if(verticalFade){
+    style.replace("%h","0");
+    style.replace("%v",QString::number(fade) );
+  }else{ //horizontal fade
+    style.replace("%v","0");
+    style.replace("%h",QString::number(fade) );
+  }
+  style.replace("%c1",colorTL);
+  style.replace("%c2",colorBR);
+  qDebug() << "LoginWidget: background stylesheet:" << style;
+  //this->setStyleSheet( style );
+}
+
+void LoginWidget::retranslateUi(){
+  //Set all the text for the widget (to easily allow changing the locale)
+  pushUserIcon->setText(tr("Select"));	
+  if(userSelected){
+    pushUserIcon->setToolTip(tr("Select an alternate user and clear the password field"));
+  }else{
+    pushUserIcon->setToolTip(tr("Select this user"));
+  }
+  pushLogin->setText(tr("Login"));
+  pushLogin->setToolTip(tr("Login to the system with the current user and password"));
+  pushViewPassword->setText(tr("Password"));
+  pushViewPassword->setToolTip(tr("Hold to view the currently entered password"));
+  listUsers->setToolTip(tr("Available users"));
+  linePassword->setToolTip(tr("Login password for the selected user"));
+  //Setup the computer/host name display
+  if( hostName.isEmpty() ){
+    this->setTitle("");
+  }else{
+    this->setTitle( QString(tr("Login to %1")).arg(hostName) );
+  }
+}

Modified: pcbsd-projects/PCDM/loginWidget.h
===================================================================
--- pcbsd-projects/PCDM/loginWidget.h	2013-01-31 17:49:51 UTC (rev 21264)
+++ pcbsd-projects/PCDM/loginWidget.h	2013-01-31 17:53:00 UTC (rev 21265)
@@ -17,8 +17,9 @@
 #include <QLineEdit>
 #include <QKeyEvent>
 #include <QAction>
+#include <QGroupBox>
 
-class LoginWidget : public QWidget
+class LoginWidget : public QGroupBox
 {
 	Q_OBJECT
 
@@ -31,6 +32,7 @@
 	QString currentPassword();
 	void setCurrentUser(QString);
 	void setUsernames(QStringList);
+        void displayHostName(QString);
 	//Set x-y size (in pixels) to scale all images (best before adding items)
 	void setIconSize(int xysize);
 	//Manually set the "back" (up/left) and "forward" (down/right) button icons
@@ -39,21 +41,26 @@
 	void setStyleSheet(QString item, QString style);
         
         void keyPressEvent(QKeyEvent *e);
+	void setBackgroundFade(bool verticalFade, int percentfade, QString colorTL, QString colorBR);
+        void retranslateUi();
   
   private:
   	QComboBox* listUsers;
   	QLineEdit* linePassword;
 	QToolButton* pushLogin;
 	QToolButton* pushViewPassword;
-	QLabel* displayIcon;
+	QToolButton* pushUserIcon;
 
 	QStringList idL;
+        QString hostName;
 	bool userSelected, pwVisible;
 
 	void updateWidget();
 
   private slots:
+	void slotUserActivated();
 	void slotUserSelected();
+	void slotUserUnselected();
   	void slotTryLogin();
   	void slotChooseUser(int);
   	void slotChangePWView();



More information about the Commits mailing list