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

List:       kde-panel-devel
Subject:    Re: [PATCH] Fifteen puzzle config revamp
From:       "Andre Magalhaes" <andrunko () gmail ! com>
Date:       2008-01-22 19:46:21
Message-ID: 7b3e4da90801221146h52057b92w1afa3281df484162 () mail ! gmail ! com
[Download RAW message or body]

Here it goes again, as proposed in the IRC.
I changed the string again to "Use custom image"

BR

On Jan 22, 2008 4:18 PM, Andre Magalhaes <andrunko@gmail.com> wrote:
> New patch with a string change as proposed by annma :)
>
> I won't upload new images as there was just a string change
>
> BR
>
>
> On Jan 22, 2008 4:03 PM, Andre Magalhaes <andrunko@gmail.com> wrote:
> > Hi all,
> >
> > Here I am again. I am trying to get the config dialogs in a sane state.
> > Another config dialog that was pissing me off was the Fifteen puzzle
> > config dialog
> > so I rewrote it.
> >
> > The code now besides the visual improvement, saves config options,
> > so when you reload the applet it will use the saved options.
> > I also reindented some part of the code to follow the applets code indentation
> >
> > Eg.: Added {  } to all if, while, for ...
> >        Removed trailing whitespaces
> >        ...
> >
> > Here are the screenshots of the old and new config dialog:
> >
> > Old config in the initial state:
> > http://www.flickr.com/photos/andrunko/2212773400/
> > Old config when "Split ..." option is selected:
> > http://www.flickr.com/photos/andrunko/2212773404/
> > Old config when "Plain .." option is selected again:
> > http://www.flickr.com/photos/andrunko/2212773406/
> >
> > New config in the initial state:
> > http://www.flickr.com/photos/andrunko/2212773410/
> > New config when "Split ..." option is selected:
> > http://www.flickr.com/photos/andrunko/2212773414/
> >
> > I  also added an action in the menu to shuffle the pieces.
> >
> > There is only one remaining issue in the new config dialog. I don't think
> > a shuffle pieces button should be there, but I can't find a way to do
> > it but in the menu (already added in the patch).
> >
> > Any feedback is welcome, if everybody agrees I will commit it.
> >
> > BR
> >
> > --
> > Andre Moreira Magalhaes (andrunko)
> > --------------------------------------------------------
> > Jabber: andrunko@gmail.com
> > MSN:   andremoreira@msn.com
> > Skype:  andrunko
> > Blog:    http://andrunko.blogspot.com
> >
>
>
>
> --
> Andre Moreira Magalhaes (andrunko)
> --------------------------------------------------------
> Jabber: andrunko@gmail.com
> MSN:   andremoreira@msn.com
> Skype:  andrunko
> Blog:    http://andrunko.blogspot.com
>



-- 
Andre Moreira Magalhaes (andrunko)
--------------------------------------------------------
Jabber: andrunko@gmail.com
MSN:   andremoreira@msn.com
Skype:  andrunko
Blog:    http://andrunko.blogspot.com

["kde4_plasma_applet_fifteen_puzzle.diff" (text/x-diff)]

Index: plasma/applets/fifteenPuzzle/src/fifteenPuzzle.h
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteenPuzzle.h	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteenPuzzle.h	(working copy)
@@ -30,16 +30,28 @@
   Q_OBJECT
   public:
     FifteenPuzzle(QObject *parent, const QVariantList &args);
+
+    void init();
     QSizeF contentSizeHint() const;
     void constraintsUpdated(Plasma::Constraints constraints);
-  
+    QList<QAction*> contextActions();
+
+  protected slots:
+    void configAccepted();
+
   private:
-    Fifteen *board;  
-    FifteenPuzzleConfig *config_dialog;
+    void updateBoard();
+    void createMenu();
 
+    Fifteen *board;
+    FifteenPuzzleConfig *configDialog;
+    QList<QAction *> actions;
+    bool usePlainPieces;
+    QString imagePath;
+    bool showNumerals;
+
   private slots:
     void showConfigurationInterface();
-
 };
 
 K_EXPORT_PLASMA_APPLET(fifteenPuzzle, FifteenPuzzle)
Index: plasma/applets/fifteenPuzzle/src/fifteen.cpp
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteen.cpp	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteen.cpp	(working copy)
@@ -29,9 +29,8 @@
 
 #define SIZE 48
 
-
-Fifteen::Fifteen(QGraphicsItem *parent) 
-	: QGraphicsRectItem(parent)
+Fifteen::Fifteen(QGraphicsItem *parent)
+    : QGraphicsRectItem(parent)
 {
   m_pixmaps.resize(16);
   m_pieces.resize(16);
@@ -53,31 +52,32 @@
   qsrand(time(0));
   clearPieces();
   m_pieces.fill(NULL);
-  for (int i=0; i<16; ++i)
-  {
-      int rand = qrand() % 16;
+  for (int i = 0; i < 16; ++i) {
+    int rand = qrand() % 16;
 
-      while (m_pieces.at(rand) != NULL)
-          rand = qrand() % 16;
+    while (m_pieces.at(rand) != NULL) {
+      rand = qrand() % 16;
+    }
 
-      m_pieces[rand] = new Piece(SIZE, i, this);
-      m_pieces[rand]->hide();
-      QObject::connect(m_pieces[rand], SIGNAL(pressed(QGraphicsItem*)), this, \
SLOT(piecePressed(QGraphicsItem*)));  +    m_pieces[rand] = new Piece(SIZE, i, this);
+    m_pieces[rand]->hide();
+    QObject::connect(m_pieces[rand], SIGNAL(pressed(QGraphicsItem*)), this, \
SLOT(piecePressed(QGraphicsItem*)));  
-      if (i == 0)
-          m_blank = m_pieces[rand];
+    if (i == 0) {
+      m_blank = m_pieces[rand];
+    }
   }
 
   if (!isSolvable()) {
-      //this is where I would rip out two pieces and swap them around, if it were a \
                plastic puzzle
-      int a = 1;
-      int b = 2;
-      if (m_pieces[a] == m_blank) { //you can't pull out a hole!
-          a = 3;
-      } else if (m_pieces[b] == m_blank) {
-          b = 0;
-      }
-      qSwap(m_pieces[a], m_pieces[b]);
+    // this is where I would rip out two pieces and swap them around, if it were a \
plastic puzzle +    int a = 1;
+    int b = 2;
+    if (m_pieces[a] == m_blank) { // you can't pull out a hole!
+      a = 3;
+    } else if (m_pieces[b] == m_blank) {
+      b = 0;
+    }
+    qSwap(m_pieces[a], m_pieces[b]);
   }
 
   updatePixmaps();
@@ -89,14 +89,11 @@
 {
   int fields[16];
   bool odd_even_solvable;
-  for (int i=0;  i<16; ++i)
-  {
+  for (int i = 0;  i < 16; ++i) {
     fields[i] = m_pieces[i]->getId();
-    if (fields[i] == 0)
-    {
+    if (fields[i] == 0) {
       fields[i] = 16;
-      switch (i)
-      {
+      switch (i) {
         case 0: case  2: case  5: case  7:
         case 8: case 10: case 13: case 15: odd_even_solvable = 1; break;
         case 1: case  3: case  4: case  6:
@@ -106,13 +103,11 @@
   }
 
   bool odd_even_permutations = 1;
-  for (int i=0; i<16; ++i)
-  {
+  for (int i = 0; i < 16; ++i) {
     int field = fields[i];
-    while (field != i+1)
-    {
-      int temp_field = fields[field-1];
-      fields[field-1] = field;
+    while (field != i + 1) {
+      int temp_field = fields[field - 1];
+      fields[field - 1] = field;
       field = temp_field;
       odd_even_permutations = !odd_even_permutations;
     }
@@ -123,8 +118,9 @@
 
 void Fifteen::updateNumerals()
 {
-  for (int i = 0; i < 16; ++i)
+  for (int i = 0; i < 16; ++i) {
     m_pieces[i]->showNumeral(m_numerals);
+  }
 
   update(boundingRect());
 }
@@ -132,7 +128,7 @@
 void Fifteen::setNumerals(bool show)
 {
   m_numerals = show;
-  updateNumerals(); 
+  updateNumerals();
 }
 
 void Fifteen::setSplitPixmap(QString path)
@@ -153,21 +149,17 @@
 {
   QPixmap pixmap;
 
-  if (!m_splitPixmap)
-  {
+  if (!m_splitPixmap) {
     pixmap = m_pixmap.scaled(SIZE, SIZE);
     m_pixmaps.fill(pixmap);
   }
-  else
-  {
-    pixmap = m_pixmap.scaled(SIZE*4, SIZE*4);
+  else {
+    pixmap = m_pixmap.scaled(SIZE * 4, SIZE * 4);
     int x = 0;
     int y = 0;
-    
-    for (int i=1; i < 16; ++i)
-    {
-      if ((i-1)%4 == 0 && i != 1)
-      {
+
+    for (int i = 1; i < 16; ++i) {
+      if ((i - 1) % 4 == 0 && i != 1) {
         x = 0;
         y = y + SIZE;
       }
@@ -176,18 +168,18 @@
     }
   }
 
-  for (int i=0;i<16;++i)
+  for (int i = 0; i < 16; ++i) {
     m_pieces[i]->setPixmap(m_pixmaps[m_pieces[i]->getId()]);
+  }
 }
 
 void Fifteen::piecePressed(QGraphicsItem *item)
 {
-  if (isAdjacent(item, m_blank))
-  {
+  if (isAdjacent(item, m_blank)) {
     QPointF pos = item->pos();
 
     QTimeLine *timer = new QTimeLine(170);
-    
+
     QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
     animation->setItem(item);
     animation->setTimeLine(timer);
@@ -198,32 +190,32 @@
     timer->start();
 
     m_blank->setPos(pos);
-   }
+  }
 }
 
 bool Fifteen::isAdjacent(QGraphicsItem *a, QGraphicsItem *b)
-{  
+{
   qreal ax = a->pos().x();
   qreal ay = a->pos().y();
-  
+
   qreal bx = b->pos().x();
   qreal by = b->pos().y();
-  
+
   /*
   qDebug() << "ax:" << ax << "ay:" << ay; 
   qDebug() << "bx:" << bx << "by:" << by;
   */
 
-  //Left
+  // Left
   if (ax + SIZE == bx && ay == by)
     return true;
-  //Right
+  // Right
   if (ax - SIZE == bx && ay == by)
     return true;
-  //Above
+  // Above
   if (ay + SIZE == by && ax == bx)
     return true;
-  //Below
+  // Below
   if (ay - SIZE == by && ax == bx)
     return true;
 
@@ -235,15 +227,13 @@
   int x = 0;
   int y = 0;
 
-  for (int i=0; i < 16; ++i)
-  {
-    if (i%4 == 0 && i != 0)
-    {
+  for (int i = 0; i < 16; ++i) {
+    if (i % 4 == 0 && i != 0) {
       x = 0;
       y = y + SIZE;
     }
-    
-    m_pieces.at(i)->setPos(x,y);
+
+    m_pieces.at(i)->setPos(x, y);
     m_pieces.at(i)->show();
     x += SIZE;
   }
Index: plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.cpp
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.cpp	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.cpp	(working copy)
@@ -22,88 +22,15 @@
 #include <QMessageBox>
 
 FifteenPuzzleConfig::FifteenPuzzleConfig(QWidget *parent)
-                  :KDialog(parent)
-{ 
-  setButtons( KDialog::Close );
-  setCaption(i18n("Configure Fifteen Puzzle"));
-  
-  ui.setupUi(mainWidget());
-  ui.gb_imageOptions->hide();
-  urlRequester = new KUrlRequester(this);
-  ui.hboxLayout->addWidget(urlRequester);
-
-  ui.rb_identical->toggle();
-  ui.cb_showNumerals->setCheckState(Qt::Checked);
-
-  QObject::connect(ui.rb_identical,SIGNAL(toggled(bool)),this,SLOT(identicalToggled(bool)));
                
-  QObject::connect(ui.rb_split,SIGNAL(toggled(bool)),this,SLOT(splitPixmapToggled(bool)));
                
-  
-  QObject::connect(urlRequester,SIGNAL(returnPressed(const \
                QString&)),this,SLOT(returnPressed(const QString&)));
-  QObject::connect(urlRequester,SIGNAL(urlSelected(const \
                KUrl&)),this,SLOT(pathSelected(const KUrl&)));
-
-
-  QObject::connect(ui.pb_shuffle,SIGNAL(clicked()),this,SIGNAL(shuffle()));
-  QObject::connect(ui.cb_showNumerals,SIGNAL(stateChanged(int)),this,SLOT(showNumeralsChanged(int)));
                
-
-}
-
-void FifteenPuzzleConfig::showNumeralsChanged(int status)
+    : KDialog(parent)
 {
-  if (status == Qt::Unchecked)
-    emit setNumerals(false);
-  else
-    emit setNumerals(true);
-}
+  setCaption(i18nc("@title:window", "Configure Fifteen Puzzle"));
+  setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
 
-void FifteenPuzzleConfig::identicalToggled(bool toggled)
-{
-  if (toggled)
-  {
-    emit setIdentical();
-    ui.cb_showNumerals->setCheckState(Qt::Checked);
-  }
-}
+  ui.setupUi(mainWidget());
 
-
-void FifteenPuzzleConfig::splitPixmapToggled(bool toggled)
-{
-  if (toggled){
-    if (urlRequester->url().hasPath())
-      pathSelected(urlRequester->url());  
-    
-    ui.gb_imageOptions->show();
-    urlRequester->setFocus();
-  }
-  else
-    ui.gb_imageOptions->hide();
+  connect(ui.pb_shuffle, SIGNAL(clicked()), this, SIGNAL(shuffle()));
 }
 
-void FifteenPuzzleConfig::pathSelected(const KUrl &url)
-{
-  QFileInfo file(url.toLocalFile());
-  if (isValidImage(file.absoluteFilePath()) && file.isFile() ) 
-    emit setSplitPixmap(file.absoluteFilePath());
-}
-
-void FifteenPuzzleConfig::returnPressed(const QString& path)
-{
-  QFileInfo file(path);
-  if (isValidImage(path) && file.isFile())
-    emit setSplitPixmap(path);
-}
-
-
-bool FifteenPuzzleConfig::isValidImage(const QString &path)
-{
-  QPixmap pixmap(path);
-  if (pixmap.isNull())
-  {
-    QMessageBox::critical(NULL, i18n("Failed to open"), i18n("Could not open \
                selected image. Please choose another."));
-    return false;
-  }
-
-  return true;
-}
-
 #include "fifteenPuzzleConfig.moc"
 
Index: plasma/applets/fifteenPuzzle/src/fifteen.h
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteen.h	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteen.h	(working copy)
@@ -27,31 +27,31 @@
 
 class Fifteen : public QObject, public QGraphicsRectItem
 {
-Q_OBJECT
+  Q_OBJECT
+  public:
+    Fifteen(QGraphicsItem *parent = 0);
 
-public:
-	Fifteen(QGraphicsItem *parent = 0 );
-  
-public slots:
-  void piecePressed(QGraphicsItem *item);
-  void setSplitPixmap(QString path);
-  void setIdentical();
-  void setNumerals(bool show);
-  void shuffle();
+  public slots:
+    void piecePressed(QGraphicsItem *item);
+    void setSplitPixmap(QString path);
+    void setIdentical();
+    void setNumerals(bool show);
+    void shuffle();
 
-private:
-  void drawPieces();
-  bool isAdjacent(QGraphicsItem *a, QGraphicsItem *b);
-  void updatePixmaps();
-  void clearPieces();
-  void updateNumerals();
-  bool isSolvable();
+  private:
+    void drawPieces();
+    bool isAdjacent(QGraphicsItem *a, QGraphicsItem *b);
+    void updatePixmaps();
+    void clearPieces();
+    void updateNumerals();
+    bool isSolvable();
 
-  QVector<Piece *> m_pieces;
-  QVector<QPixmap> m_pixmaps;
-  QGraphicsItem *m_blank;
-  bool m_splitPixmap;
-  QPixmap m_pixmap;
-  bool m_numerals;
+    QVector<Piece *> m_pieces;
+    QVector<QPixmap> m_pixmaps;
+    QGraphicsItem *m_blank;
+    bool m_splitPixmap;
+    QPixmap m_pixmap;
+    bool m_numerals;
 };
+
 #endif
Index: plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.h
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.h	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.h	(working copy)
@@ -25,33 +25,16 @@
 
 #include "ui_fifteenPuzzleConfig.h"
 
-class FifteenPuzzleConfig : public KDialog 
+class FifteenPuzzleConfig : public KDialog
 {
   Q_OBJECT
-
   public:
-    FifteenPuzzleConfig(QWidget *parent=0);
+    FifteenPuzzleConfig(QWidget *parent = 0);
 
-  private slots:
-    void returnPressed(const QString& path);
-    void pathSelected(const KUrl& url);
-    void splitPixmapToggled(bool toggled);
-    void identicalToggled(bool toggled);
-    void showNumeralsChanged(int state);
-  
-  private:
-    bool isValidImage(const QString &path);
-
     Ui::fifteenPuzzleConfig ui;
-    KUrlRequester *urlRequester;
 
-  
   signals:
-    void setIdentical();
-    void setSplitPixmap(QString path);
-    void setNumerals(bool show);
     void shuffle();
 };
 
 #endif
-
Index: plasma/applets/fifteenPuzzle/src/piece.cpp
===================================================================
--- plasma/applets/fifteenPuzzle/src/piece.cpp	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/piece.cpp	(working copy)
@@ -17,18 +17,19 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  ***************************************************************************/
 
-// Thanks to ThomasZ and Jens B-W for making this prettier than just some 
+// Thanks to ThomasZ and Jens B-W for making this prettier than just some
 // off-centered text and gradients ;)
 
 #include "piece.h"
+
 #include <QPen>
 #include <QPainter>
-#include <QDebug>   
+#include <QDebug>
 #include <QGraphicsSceneMouseEvent>
 #include <QFontMetrics>
 
 Piece::Piece(int size, int id, QGraphicsItem *parent)
-          : QGraphicsPixmapItem(parent)
+    : QGraphicsPixmapItem(parent)
 {
   m_size = size;
   m_id = id;
@@ -46,17 +47,18 @@
 }
 
 void Piece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
-           QWidget *widget)
+                  QWidget *widget)
 {
-
-  if (m_id == 0)
+  if (m_id == 0) {
     return;
+  }
 
   QGraphicsPixmapItem::paint(painter, option, widget);
 
-  if (!m_numeral)
+  if (!m_numeral) {
     return;
- 
+  }
+
   QFont font = painter->font();
   font.setBold(true);
   font.setPointSize(14);
@@ -66,21 +68,26 @@
   QString text = QString::number(m_id);
 
   QPen pen = painter->pen();
-  
-  pen.setColor(QColor(0,0,0,90));
+
+  pen.setColor(QColor(0, 0, 0, 90));
   painter->setPen(pen);
-  painter->drawText( ((m_size/2) - m.width(text)/2)+2, ((m_size/2) + \
                m.ascent()/2)+2, text);
-  
+  painter->drawText(((m_size / 2) - m.width(text) / 2) + 2,
+                    ((m_size / 2) + m.ascent() / 2) + 2,
+                    text);
+
   pen.setColor(QColor(Qt::white));
   painter->setPen(pen);
-  painter->drawText( (m_size/2) - m.width(text)/2, (m_size/2) + m.ascent()/2, text);
+  painter->drawText((m_size / 2) - m.width(text) / 2,
+                    (m_size / 2) + m.ascent() / 2,
+                    text);
 }
 
 void Piece::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
   Q_UNUSED(event);
-  if (m_id == 0)
+  if (m_id == 0) {
     return;
+  }
 
   emit pressed(this);
 }
Index: plasma/applets/fifteenPuzzle/src/fifteenPuzzle.cpp
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteenPuzzle.cpp	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteenPuzzle.cpp	(working copy)
@@ -20,39 +20,106 @@
 #include "fifteenPuzzle.h"
 
 FifteenPuzzle::FifteenPuzzle(QObject *parent, const QVariantList &args)
-    : Plasma::Applet(parent, args), config_dialog(0)
+    : Plasma::Applet(parent, args), configDialog(0)
 {
   setHasConfigurationInterface(true);
   board = new Fifteen(this);
   board->setRect(0, 0, 192, 192); // 48 * 4 = 192
 }
 
+void FifteenPuzzle::init()
+{
+  createMenu();
+
+  KConfigGroup cg = config();
+
+  usePlainPieces = cg.readEntry("UsePlainPieces", true);
+  imagePath = cg.readEntry("ImagePath", QString());
+  showNumerals = cg.readEntry("ShowNumerals", true);
+
+  // make sure nobody messed up with the config file
+  if (!usePlainPieces &&
+      (imagePath.isEmpty() ||
+       QPixmap(imagePath).isNull())) {
+    usePlainPieces = true;
+  }
+
+  updateBoard();
+}
+
 QSizeF FifteenPuzzle::contentSizeHint() const
-{ 
+{
   return board->boundingRect().size();
 }
 
 void FifteenPuzzle::constraintsUpdated(Plasma::Constraints constraints)
 {
-  if (constraints & Plasma::SizeConstraint)
-  {
+  if (constraints & Plasma::SizeConstraint) {
     QSizeF size = this->contentSize();
     board->resetTransform();
-    board->scale(size.width()/192,size.height()/192);
+    board->scale(size.width() / 192, size.height() / 192);
   }
 }
 
+QList<QAction*> FifteenPuzzle::contextActions()
+{
+  return actions;
+}
+
 void FifteenPuzzle::showConfigurationInterface()
 {
-  if (config_dialog == 0)
-  {
-    config_dialog = new FifteenPuzzleConfig();
-    QObject::connect(config_dialog,SIGNAL(setSplitPixmap(QString)),board, \
                SLOT(setSplitPixmap(QString)));
-    QObject::connect(config_dialog,SIGNAL(setIdentical()),board, \
                SLOT(setIdentical()));
-    QObject::connect(config_dialog,SIGNAL(setNumerals(bool)),board, \
                SLOT(setNumerals(bool)));
-    QObject::connect(config_dialog,SIGNAL(shuffle()),board, SLOT(shuffle()));
+  if (configDialog == 0) {
+    configDialog = new FifteenPuzzleConfig();
+    connect(configDialog, SIGNAL(shuffle()), board, SLOT(shuffle()));
+    connect(configDialog, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
+    connect(configDialog, SIGNAL(okClicked()), this, SLOT(configAccepted()));
   }
-  config_dialog->show();
+
+  if (usePlainPieces) {
+    configDialog->ui.rb_identical->setChecked(true);
+  }
+  else {
+    configDialog->ui.rb_split->setChecked(true);
+  }
+  configDialog->ui.urlRequester->setUrl(imagePath);
+  configDialog->ui.cb_showNumerals->setChecked(showNumerals);
+  configDialog->show();
 }
 
+void FifteenPuzzle::configAccepted()
+{
+  KConfigGroup cg = config();
+
+  usePlainPieces = configDialog->ui.rb_identical->isChecked();
+  imagePath = configDialog->ui.urlRequester->url().path();
+  showNumerals = configDialog->ui.cb_showNumerals->isChecked();
+
+  cg.writeEntry("UsePlainPieces", usePlainPieces);
+  cg.writeEntry("ImagePath", imagePath);
+  cg.writeEntry("ShowNumerals", showNumerals);
+
+  updateBoard();
+
+  emit configNeedsSaving();
+}
+
+void FifteenPuzzle::updateBoard()
+{
+  if (usePlainPieces) {
+    board->setIdentical();
+  }
+  else {
+    board->setSplitPixmap(imagePath);
+    board->setNumerals(showNumerals);
+  }
+}
+
+void FifteenPuzzle::createMenu()
+{
+  QAction *shuffle = new QAction(i18n("Shuffle Pieces"), this);
+  actions.append(shuffle);
+  connect(shuffle, SIGNAL(triggered(bool)), board, SLOT(shuffle()));
+}
+
 #include "fifteenPuzzle.moc"
+
Index: plasma/applets/fifteenPuzzle/src/piece.h
===================================================================
--- plasma/applets/fifteenPuzzle/src/piece.h	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/piece.h	(working copy)
@@ -24,24 +24,25 @@
 #include <QObject>
 
 class Piece : public QObject, public QGraphicsPixmapItem
-{  
-Q_OBJECT
+{
+  Q_OBJECT
 
-public:
-	Piece(int size, int id, QGraphicsItem * parent);
-  int getId();
-  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget \
                *widget);
-  void showNumeral(bool show);
+  public:
+    Piece(int size, int id, QGraphicsItem * parent);
+    int getId();
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget \
*widget); +    void showNumeral(bool show);
 
-private:
-  int m_id;
-  int m_size;
-  bool m_numeral;
- 
-protected:
-  void mousePressEvent(QGraphicsSceneMouseEvent *event);  
+  private:
+    int m_id;
+    int m_size;
+    bool m_numeral;
 
-signals:
-  void pressed(QGraphicsItem *item);
+  protected:
+    void mousePressEvent(QGraphicsSceneMouseEvent *event);
+
+  signals:
+    void pressed(QGraphicsItem *item);
 };
+
 #endif
Index: plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.ui
===================================================================
--- plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.ui	(revision 764883)
+++ plasma/applets/fifteenPuzzle/src/fifteenPuzzleConfig.ui	(working copy)
@@ -5,68 +5,66 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>272</width>
-    <height>266</height>
+    <width>278</width>
+    <height>254</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Configure Fifteen Puzzle</string>
   </property>
   <layout class="QVBoxLayout" >
-   <property name="leftMargin" >
-    <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>
-    <widget class="QGroupBox" name="groupBox" >
+    <widget class="QGroupBox" name="gb_appearance" >
      <property name="title" >
-      <string>Graphics</string>
+      <string>Appearance</string>
      </property>
+     <property name="flat" >
+      <bool>true</bool>
+     </property>
      <layout class="QVBoxLayout" >
       <item>
        <widget class="QRadioButton" name="rb_identical" >
         <property name="text" >
-         <string>Plain pieces</string>
+         <string>Use plain pieces</string>
         </property>
+        <property name="checked" >
+         <bool>true</bool>
+        </property>
        </widget>
       </item>
       <item>
        <widget class="QRadioButton" name="rb_split" >
         <property name="text" >
-         <string>Split image into puzzle pieces</string>
+         <string>Use custom image</string>
         </property>
        </widget>
       </item>
-     </layout>
-    </widget>
-   </item>
-   <item>
-    <widget class="QGroupBox" name="gb_imageOptions" >
-     <property name="title" >
-      <string>Image Options</string>
-     </property>
-     <layout class="QVBoxLayout" >
       <item>
        <layout class="QHBoxLayout" >
         <item>
-         <widget class="QLabel" name="label_3" >
+         <widget class="QLabel" name="lbl_image" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
           <property name="text" >
-           <string>File:</string>
+           <string>Image:</string>
           </property>
          </widget>
         </item>
+        <item>
+         <widget class="KUrlRequester" name="urlRequester" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
        </layout>
       </item>
       <item>
        <widget class="QCheckBox" name="cb_showNumerals" >
+        <property name="enabled" >
+         <bool>false</bool>
+        </property>
         <property name="text" >
          <string>Show Numerals</string>
         </property>
@@ -76,41 +74,23 @@
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" >
-     <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" >
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="pb_shuffle" >
-       <property name="text" >
-        <string>Shuffle Pieces</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" >
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
+    <widget class="QGroupBox" name="gb_actions" >
+     <property name="title" >
+      <string>Actions</string>
+     </property>
+     <property name="flat" >
+      <bool>true</bool>
+     </property>
+     <layout class="QVBoxLayout" >
+      <item>
+       <widget class="QPushButton" name="pb_shuffle" >
+        <property name="text" >
+         <string>Shuffle Pieces</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
    </item>
    <item>
     <spacer>
@@ -120,13 +100,69 @@
      <property name="sizeHint" >
       <size>
        <width>20</width>
-       <height>40</height>
+       <height>0</height>
       </size>
      </property>
     </spacer>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>KUrlRequester</class>
+   <extends>QFrame</extends>
+   <header>kurlrequester.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>rb_split</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>cb_showNumerals</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>146</x>
+     <y>81</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>146</x>
+     <y>146</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>rb_split</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>lbl_image</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>146</x>
+     <y>81</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>52</x>
+     <y>114</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>rb_split</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>urlRequester</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>146</x>
+     <y>81</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>171</x>
+     <y>114</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>



_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


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

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