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

List:       kde-devel
Subject:    [patch] kcron modify task new enhanced GUI
From:       "dave selby" <dave6502 () googlemail ! com>
Date:       2007-07-31 19:27:50
Message-ID: f52017b60707311227w1ad43634t8a34e3c7a7f339d4 () mail ! gmail ! com
[Download RAW message or body]

I have patched the 'modify task' GUI adding the following features ....


Added KTitleWidget

Selecting an invalid configuration ie no month activates a wizard
guiding the user through what needs to be fixed to make the Kcron task
work

selected buttons are now easier to view with blue (colour contrast)
lettering yet more subtle than the stark blue and white of selected
buttons in KDE3 kcron.

unticking 'enabled' greys out the GUI options to remind the user that
the task is not enabled


I don't know if I am breaking any KDE guidelines and would welcome
feedback before I commit and move onto 'modify variables'. Especially
with regard to the blue text buttons and any code style improvements.

Cheers

Dave






-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

["kcron.diff" (text/x-patch)]

Index: kttask.cpp
===================================================================
--- kttask.cpp	(revision 694793)
+++ kttask.cpp	(working copy)
@@ -25,6 +25,8 @@
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 
+#include "qstyleoption.h"
+#include "qstylepainter.h"
 
 #include <klocale.h>
 #include <kfiledialog.h>
@@ -34,6 +36,7 @@
 #include <kdialog.h>
 #include <kstandardshortcut.h>
 #include <kstandarddirs.h>
+#include <ktitlewidget.h>
 #include "cttask.h"
 
 #include "kticon.h"
@@ -42,7 +45,7 @@
 {
 public:
    KTPushButton(QWidget * parent)
-     : QPushButton(parent), isSelected(false), isDirty(false)
+     : QPushButton(parent), isDirty(false)
    {
       updatePalette();
    }
@@ -51,12 +54,10 @@
    {
       palNormal = ((QWidget *)parent())->palette();
       palSelected = palNormal;
-      for(int cg = (int) QPalette::Disabled; cg < (int) QPalette::NColorGroups; \
cg++) +      for(int cg = (int) QPalette::Active; cg < (int) QPalette::NColorGroups; \
cg++)  {
-        palSelected.setColor((QPalette::ColorGroup)cg, QPalette::Button,
+        palSelected.setColor((QPalette::ColorGroup)cg, QPalette::ButtonText,
                      palSelected.color((QPalette::ColorGroup)cg, \
                QPalette::Highlight));
-        palSelected.setColor((QPalette::ColorGroup)cg, QPalette::ButtonText,
-                     palSelected.color((QPalette::ColorGroup)cg, \
QPalette::HighlightedText));  }
       isDirty = true;
    }
@@ -71,40 +72,32 @@
      return QPushButton::event(e);
    }
 
-   void paintEvent(QPaintEvent* p)
+   void paintEvent(QPaintEvent*)
    {
-     QPushButton::paintEvent(p);
-   }
+     QStylePainter p(this);
+     QStyleOptionButton option;
+     initStyleOption(&option);
 
-   void drawButton ( QPainter* /*p*/ )
-   {
-     if (isDirty || (isChecked() != isSelected)) // Prevent infinite recursion
+     if (isDirty || isChecked())
      {
        isDirty = false;
-       isSelected = isChecked();
-       if (isSelected)
-         setPalette(palSelected);
-       else
-         setPalette(palNormal);
+       if (isChecked())
+       {
+         option.palette = palSelected;
+         QFont f=p.font();
+         f.setBold(true);
+         p.setFont(f);
+       }
      }
+   p.drawControl(QStyle::CE_PushButton, option);
    }
-   void drawButtonLabel ( QPainter *p )
-   {
-     p->save();
-     if (isChecked())
-     {
-       QFont f = p->font();
-       f.setUnderline(true);
-       p->setFont(f);
-     }
-     p->restore();
-   }
-   bool isSelected;
+
    bool isDirty;
    QPalette palSelected;
    QPalette palNormal;
 };
 
+
 KTTask::KTTask(CTTask* _cttask, const QString & _caption)
        :KDialog( 0 )
 {
@@ -116,6 +109,15 @@
   QVBoxLayout *ml = new QVBoxLayout(main);
   ml->setSpacing(KDialog::spacingHint());
 
+  QHBoxLayout *h0 = new QHBoxLayout();
+  h0->setSpacing(KDialog::spacingHint());
+  ml->addLayout(h0); 
+
+  // top title widget
+  titleWidget = new KTitleWidget(main);
+  setuptitleWidget();
+  h0->addWidget(titleWidget);
+
   QHBoxLayout *h1 = new QHBoxLayout();
   h1->setSpacing(KDialog::spacingHint());
   ml->addLayout(h1);
@@ -140,13 +142,6 @@
     leUser->hide();
   }
 
-  // icon
-  labIcon = new QLabel(main);
-  labIcon->setObjectName("labIcon");
-  labIcon->setFixedSize(32, 32);
-  h1->addStretch( 1 );
-  h1->addWidget( labIcon );
-
   // comment
   QHBoxLayout *h2 = new QHBoxLayout();
   h2->setSpacing( KDialog::spacingHint() );
@@ -199,7 +194,7 @@
   chkEnabled->setChecked(cttask->enabled);
   h3a->addWidget( chkEnabled );
 
-  // enabled
+  // silent
   chkSilent = new QCheckBox(i18n("&Silent"), main);
   chkSilent->setObjectName("chkSilent");
   chkSilent->setChecked(cttask->silent);
@@ -258,7 +253,6 @@
       vdays->addLayout(hdays);
     }
 
-
     day = new KTPushButton(bgDayOfMonth);
     day->setFixedSize(25, 25);
     day->setText(tmp.setNum(dm));
@@ -326,7 +320,6 @@
   labAM->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
   v4->addWidget( labAM );
 
-
   for (int ho = 0; ho <= 23; ho++)
   {
     pbHour[ho] = new KTPushButton(bgHour);
@@ -437,34 +430,63 @@
 
   // connect them up
   connect(pbBrowse, SIGNAL(clicked()), SLOT(slotBrowse()));
+  connect(pbBrowse, SIGNAL(clicked()), SLOT(slotWizard()));
+
   connect(leCommand, SIGNAL(textChanged(const QString&)),
     SLOT(slotCommandChanged()));
+  connect(leCommand, SIGNAL(textChanged(const QString&)),
+    SLOT(slotWizard()));
+
+  connect(chkEnabled, SIGNAL(clicked()), SLOT(slotEnabled()));
+
   connect(cbEveryDay, SIGNAL(clicked()), SLOT(slotDailyChanged()));
+  connect(cbEveryDay, SIGNAL(clicked()), SLOT(slotWizard()));
+
   connect(this, SIGNAL(okClicked()), SLOT(slotOK()));
   connect(this, SIGNAL(cancelClicked()), SLOT(slotCancel()));
+
   connect(pbAllMonths, SIGNAL(clicked()), SLOT(slotAllMonths()));
+  connect(pbAllMonths, SIGNAL(clicked()), SLOT(slotWizard()));
+
   for (int mo = 1; mo <= 12; mo++) {
     connect(cbMonth[mo], SIGNAL(clicked()), SLOT(slotMonthChanged()));
+    connect(cbMonth[mo], SIGNAL(clicked()), SLOT(slotWizard()));
   }
+
   connect(pbAllDaysOfMonth, SIGNAL(clicked()), SLOT(slotAllDaysOfMonth()));
+  connect(pbAllDaysOfMonth, SIGNAL(clicked()), SLOT(slotWizard()));
+
   for (int dm = 1; dm <= 31; dm++)
   {
     connect(pbDayOfMonth[dm], SIGNAL(clicked()), SLOT(slotDayOfMonthChanged()));
+    connect(pbDayOfMonth[dm], SIGNAL(clicked()), SLOT(slotWizard()));
   }
+
   connect(pbAllDaysOfWeek, SIGNAL(clicked()), SLOT(slotAllDaysOfWeek()));
+  connect(pbAllDaysOfWeek, SIGNAL(clicked()), SLOT(slotWizard()));
+
   for (int dw = 1; dw <= 7; dw++)
   {
     connect(cbDayOfWeek[dw], SIGNAL(clicked()), SLOT(slotDayOfWeekChanged()));
+    connect(cbDayOfWeek[dw], SIGNAL(clicked()), SLOT(slotWizard()));
   }
+
   connect(pbAllHours, SIGNAL(clicked()), SLOT(slotAllHours()));
+  connect(pbAllHours, SIGNAL(clicked()), SLOT(slotWizard()));
+
   for (int ho = 0; ho <= 23; ho++)
   {
     connect(pbHour[ho], SIGNAL(clicked()), SLOT(slotHourChanged()));
+    connect(pbHour[ho], SIGNAL(clicked()), SLOT(slotWizard()));
   }
+
   connect(pbAllMinutes, SIGNAL(clicked()), SLOT(slotAllMinutes()));
+  connect(pbAllMinutes, SIGNAL(clicked()), SLOT(slotWizard()));
+
   for (int mi = 0; mi <= 55; mi+=5)
   {
     connect(pbMinute[mi], SIGNAL(clicked()), SLOT(slotMinuteChanged()));
+    connect(pbMinute[mi], SIGNAL(clicked()), SLOT(slotWizard()));
   }
 
   // key acceleration
@@ -483,12 +505,31 @@
   slotDayOfWeekChanged();
   slotHourChanged();
   slotMinuteChanged();
+
+  slotEnabled();
+  slotWizard();
 }
 
 KTTask::~KTTask()
 {
 }
 
+void KTTask::setuptitleWidget(const QString &comment)
+{
+  if (comment == "")
+  {
+    titleWidget->setText(i18n("Add or modify a Kcron task"));  
+    titleWidget->setComment(i18n("<i>This task has a valid configuration ...</i>"));
+    titleWidget->setPixmap(KIcon(KTIcon::task(false)), KTitleWidget::ImageRight);
+  }  
+  else  
+  {
+    titleWidget->setText(i18n("Kcron wizard"));  
+    titleWidget->setComment(comment);
+    titleWidget->setPixmap(KIcon(KTIcon::wizard(false)), KTitleWidget::ImageRight);
+  }
+}
+
 void KTTask::slotCommandChanged()
 {
   /*
@@ -508,8 +549,8 @@
   else
     labIcon->setPixmap(qp);
   */
-
-  labIcon->setPixmap(KTIcon::task(false));
+  // FIXME get the icons to work :)
+  //labIcon->setPixmap(KTIcon::task(false));
   return;
 }
 
@@ -559,9 +600,25 @@
   slotDayOfWeekChanged();
 }
 
-// Override the default OK handler in QDialog
-// to avoid auto dialog hiding.
-void KTTask::accept() {}
+void KTTask::slotEnabled()
+{
+  bool enabled = chkEnabled->isChecked();  
+  labUser->setEnabled(enabled);
+  leUser->setEnabled(enabled);
+  leComment->setEnabled(enabled);
+  labComment->setEnabled(enabled);
+  leCommand->setEnabled(enabled);
+  labCommand->setEnabled(enabled);
+  pbBrowse->setEnabled(enabled);
+  chkSilent->setEnabled(enabled);
+  bgMonth->setEnabled(enabled);
+  bgDayOfMonth->setEnabled(enabled);
+  bgDayOfWeek->setEnabled(enabled);
+  bgEveryDay->setEnabled(enabled);
+  bgHour->setEnabled(enabled);
+  bgMinute->setEnabled(enabled);
+  slotWizard();
+}
 
 void KTTask::slotOK()
         
@@ -597,16 +654,68 @@
     }
   }
 
-  // Now validate
-  QString message(i18n("Please enter the following to schedule the task:\n"));
-  QString sep("\n- ");
-  bool showMessage(false);
+  // save work in process
+  if (!cttask->user.empty())
+  {
+    cttask->user = (const char*)QFile::encodeName(leUser->text());
+  }
+  else
+  {
+    cttask->user = "";
+  }
 
+  cttask->comment = (const char *)leComment->text().toLocal8Bit();
+  cttask->command = (const char *)leCommand->text().toLocal8Bit();
+  cttask->enabled = chkEnabled->isChecked();
+  cttask->silent = chkSilent->isChecked();
+
+  for (int mo = 1; mo <= 12; mo++)
+  {
+    cttask->month.set(mo, cbMonth[mo]->isChecked());
+  }
+
+  for (int dm = 1; dm <= 31; dm++)
+  {
+    cttask->dayOfMonth.set(dm, pbDayOfMonth[dm]->isChecked());
+  }
+  for (int dw = 1; dw <= 7; dw++)
+  {
+    cttask->dayOfWeek.set(dw, cbDayOfWeek[dw]->isChecked());
+  }
+  for (int ho = 0; ho <= 23; ho++)
+  {
+    cttask->hour.set(ho, pbHour[ho]->isChecked());
+  }
+  for (int mi = 0; mi <= 59; mi++)
+  {
+    cttask->minute.set(mi, false);
+  }
+  for (int mi1 = 0; mi1 <= 55; mi1+=5)
+  {
+    cttask->minute.set(mi1, pbMinute[mi1]->isChecked());
+  }
+  close();
+}
+
+
+void KTTask::slotWizard()
+
+{
+  bool error(false);
+
+
+  if (!chkEnabled->isChecked())
+  {
+    setuptitleWidget(i18n("<i>Please check 'Enabled' to edit this task ...</i>"));
+    leCommand->setFocus();
+    error = true;
+  }
+
   if (leCommand->text().isEmpty())
   {
-    message += sep + i18n("the program to run");
+    setuptitleWidget(i18n("<i>Please browse for a program to execute ...</i>"));
     leCommand->setFocus();
-    showMessage = true;
+    error = true;
   }  
   
   // make sure the file name is a good one if we have an
@@ -633,36 +742,34 @@
   if (KStandardDirs::findExe(cmdstr, pathstr, KStandardDirs::IgnoreExecBit) != "") \
found = true;  if (KStandardDirs::findExe(cmdstr, pathstr) != "") exec = true;
   
-  if (found && !exec) 
+  if (found && !exec && !error) 
   {
-    message += sep + i18n("an executable program to run");
+    setuptitleWidget(i18n("<i>Please select an executable program ...</i>"));
     leCommand->setFocus();
-    showMessage = true;
+    error = true;
   }
 
-  if (!found)
+  if (!found && !error)
   {
-    message += sep + i18n("a valid program to run");
+    setuptitleWidget(i18n("<i>Please browse for a program to execute ...</i>"));
     leCommand->setFocus();
-    showMessage = true;
+    error = true;
   }
   
-  // the times
+  // the months
   bool valid(false);
   for (int mo = 1; mo <= 12; mo++)
   {
     if (cbMonth[mo]->isChecked()) valid = true;
   }
-  if (!valid)
+  if (!valid && !error)
   {
-    message += sep + i18n("the months");
-    if (!showMessage)
-    {
-      cbMonth[1]->setFocus();
-    }
-    showMessage = true;
+    setuptitleWidget(i18n("<i>Please select from 'Months' section ...</i>"));
+    cbMonth[1]->setFocus();
+    error = true;
   }
 
+  // the days
   valid = false;
   for (int dm = 1; dm <= 31; dm++)
   {
@@ -673,97 +780,45 @@
     if (cbDayOfWeek[dw]->isChecked()) valid = true;
   }
 
-  if (!valid)
+  if (!valid && !error)
   {
-    message += sep +
-      i18n("either the days of the month or the days of the week");
-    if (!showMessage)
-    {
-      pbDayOfMonth[1]->setFocus();
-    }
-    showMessage = true;
+    setuptitleWidget(i18n("<i>Please select from either the 'Days of Month' or the \
'Days of Week' ...</i>")); +    pbDayOfMonth[1]->setFocus();
+    error = true;
   }
 
+  // the hours
   valid = false;
   for (int ho = 0; ho <= 23; ho++)
   {
     if (pbHour[ho]->isChecked()) valid = true;
   }
 
-  if (!valid)
+  if (!valid && !error)
   {
-    message += sep + i18n("the hours");
-    if (!showMessage)
-    {
-      pbHour[0]->setFocus();
-    }
-    showMessage = true;
+    setuptitleWidget(i18n("<i>Please select from the 'Hours' section ...</i>"));
+    pbHour[0]->setFocus();
+    error = true;
   }
 
+  // the mins
   valid = false;
   for (int mi1 = 0; mi1 <= 55; mi1+=5)
   {
     if (pbMinute[mi1]->isChecked()) valid = true;
   }
 
-  if (!valid)
+  if (!valid && !error)
   {
-    message += sep + i18n("the minutes");
-    if (!showMessage)
-    {
-      pbMinute[0]->setFocus();
-    }
-    showMessage = true;
+    setuptitleWidget(i18n("<i>Please select from the 'Minutes' section ...</i>"));
+    pbMinute[0]->setFocus();
+    error = true;
   }
 
-  if (showMessage)
+  if (!error) 
   {
-    KMessageBox::information(this, message);
-    return;
+    setuptitleWidget();
   }
-
-  // save work in process
-  if (!cttask->user.empty())
-  {
-    cttask->user = (const char*)QFile::encodeName(leUser->text());
-  }
-  else
-  {
-    cttask->user = "";
-  }
-
-  cttask->comment = (const char *)leComment->text().toLocal8Bit();
-  cttask->command = (const char *)leCommand->text().toLocal8Bit();
-  cttask->enabled = chkEnabled->isChecked();
-  cttask->silent = chkSilent->isChecked();
-
-  for (int mo = 1; mo <= 12; mo++)
-  {
-    cttask->month.set(mo, cbMonth[mo]->isChecked());
-  }
-
-  for (int dm = 1; dm <= 31; dm++)
-  {
-    cttask->dayOfMonth.set(dm, pbDayOfMonth[dm]->isChecked());
-  }
-  for (int dw = 1; dw <= 7; dw++)
-  {
-    cttask->dayOfWeek.set(dw, cbDayOfWeek[dw]->isChecked());
-  }
-  for (int ho = 0; ho <= 23; ho++)
-  {
-    cttask->hour.set(ho, pbHour[ho]->isChecked());
-  }
-  for (int mi = 0; mi <= 59; mi++)
-  {
-    cttask->minute.set(mi, false);
-  }
-  for (int mi1 = 0; mi1 <= 55; mi1+=5)
-  {
-    cttask->minute.set(mi1, pbMinute[mi1]->isChecked());
-  }
-
-  close();
 }
 
 void KTTask::slotCancel()
@@ -787,7 +842,6 @@
         i18n("Only local or mounted files can be executed by crontab."));
     }
   }
-
   leCommand->setFocus();
 }
 
Index: kticon.h
===================================================================
--- kticon.h	(revision 694793)
+++ kticon.h	(working copy)
@@ -26,6 +26,7 @@
 
   static QPixmap getMiniIcon(const QString& name);
   static QPixmap getIcon(const QString& name);
+  static QPixmap getMaxIcon(const QString& name);
   static QPixmap application(bool mini);
   static QPixmap system(bool mini);
   static QPixmap user(bool mini);
@@ -37,6 +38,7 @@
   static QPixmap path(bool mini);
   static QPixmap tasks(bool mini);
   static QPixmap task(bool mini);
+  static QPixmap wizard(bool mini);
 
 };
 
Index: kticon.cpp
===================================================================
--- kticon.cpp	(revision 694793)
+++ kticon.cpp	(working copy)
@@ -28,6 +28,11 @@
   return BarIcon(name);
 }
 
+QPixmap KTIcon::getMaxIcon(const QString& name)
+{
+  return DesktopIcon(name);
+}
+
 QPixmap KTIcon::application(bool mini)
 {
   if (mini)
@@ -113,5 +118,14 @@
   if (mini)
     return getMiniIcon("gear");
   else
-    return getIcon("gear");
+    return getMaxIcon("gear");
 }
+
+// FIXME Change this to a wizard.png when theme oxygen supports it
+QPixmap KTIcon::wizard(bool mini)
+{
+  if (mini)
+    return getMiniIcon("dialog-information");
+  else
+    return getMaxIcon("dialog-information");
+}
Index: kttask.h
===================================================================
--- kttask.h	(revision 694793)
+++ kttask.h	(working copy)
@@ -13,6 +13,8 @@
 #define KTTASK_H
 
 #include <kdialog.h>
+#include <kicon.h>
+#include <ktitlewidget.h>
 //Added by qt3to4:
 #include <QLabel>
 
@@ -51,6 +53,11 @@
   void slotBrowse();
 
 /**
+  * Control the task title bar.
+  */
+  void setuptitleWidget(const QString &comment="");
+
+/**
   * Command has been changed.  Refresh icon.
   */
   void slotCommandChanged();
@@ -61,9 +68,9 @@
   void slotDailyChanged();
 
 /**
-  * Override QDialog::accept ()
+  * Enable / Disable buttons
   */
-  void accept(); 
+  void slotEnabled();
 
 /**
   * Apply changes and close.
@@ -71,6 +78,11 @@
   void slotOK();
 
 /**
+  * Run the wizard.
+  */
+  void slotWizard();
+
+/**
   * Cancel and close.
   */
   void slotCancel();
@@ -135,6 +147,7 @@
 
   // Widgets.
 
+  KTitleWidget*   titleWidget;
   QLabel*         labUser;
   QLineEdit*      leUser;
 



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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