]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/iconpalette.C
partial fonts fix. Like Juergen said we really need our own dialog.
[lyx.git] / src / frontends / qt2 / iconpalette.C
index 724aff44b56047d5ea1df533c15f9622bf4f89df..8f09504414eca60732800bafa4de4d01325117c1 100644 (file)
@@ -1,15 +1,21 @@
 /**
  * \file iconpalette.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "debug.h"
+
 #include "iconpalette.h"
 
 #include <qlayout.h>
@@ -21,9 +27,10 @@ using std::endl;
 using std::make_pair;
 using std::vector;
 using std::max;
+
 int const button_size = 40;
+
+
 IconPalette::IconPalette(QWidget * parent, char const * name)
        : QWidget(parent, name), maxcol_(-1)
 {
@@ -41,7 +48,7 @@ void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
        p->setFixedSize(button_size, button_size);
        p->setPixmap(pixmap);
        QToolTip::add(p, tooltip.c_str());
-       connect(p, SIGNAL(clicked()), this, SLOT(clicked())); 
+       connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
        buttons_.push_back(make_pair(p, name));
 }
 
@@ -61,47 +68,52 @@ void IconPalette::clicked()
 
 void IconPalette::resizeEvent(QResizeEvent * e)
 {
-       lyxerr << "resize panel to " << e->size().width() << "," << e->size().height() << endl;
+       QWidget::resizeEvent(e);
+
+       lyxerr[Debug::GUI] << "resize panel to "
+               << e->size().width() << "," << e->size().height() << endl;
+
        int maxcol = e->size().width() / button_size;
+
        if (!layout_->isEmpty() && maxcol == maxcol_)
                return;
 
-       lyxerr << "doing layout !" << maxcol << " " << width() << endl;
-       lyxerr << "before is " << maxcol_ << endl; 
+       int cols(width() / button_size);
+       int rows = max(int(buttons_.size() / cols), 1);
+       if (buttons_.size() % cols)
+               ++rows;
+
+       lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
+               << cols << "x" << rows << " grid." << endl;
+
        setUpdatesEnabled(false);
+
        // clear layout
        QLayoutIterator lit = layout_->iterator();
        while (lit.current()) {
                lit.takeCurrent();
        }
-                
+
        layout_->invalidate();
+
        vector<Button>::const_iterator it(buttons_.begin());
        vector<Button>::const_iterator const end(buttons_.end());
 
-       int row = 0;
-       int col = 0;
-        
-       for (; it != end; ++it) {
-               layout_->addWidget(it->first, row, col++);
-               if (col >= maxcol) {
-                       col = 0;
-                       ++row;
+       for (int i = 0; i < rows; ++i) {
+               for (int j = 0; j < cols; ++j) {
+                       layout_->addWidget(it->first, i, j);
+                       ++it;
+                       if (it == end)
+                               goto out;
                }
        }
 
-       maxcol_ = maxcol;
-       // this is OK because width won't change, and we have the check above
-       setGeometry(x(), y(), width(), (row + 1) * button_size);
-       repaint();
-       lyxerr << "after is " << row << "," << maxcol << endl; 
+out:
+
+       resize(cols * button_size, rows * button_size);
+
+       maxcol_ = cols;
+
        setUpdatesEnabled(true);
        update();
 }