Abdelrazak Younes wrote:
Abdelrazak Younes wrote:
Ozgur Ugras BARAN wrote:
when iconpalette detached from the math dialog, the iconpalette widget
width may become too large to fit to the screen.

the attached patch solves the layout problems.

i restrict the icon panels to have 6 columns (which i think is fine).

the patch simplifies the code quite a bit btw.

i don't feel like spending too much effort on this since math panel will go anyway (i suggest having a nice math toolbar for 1.6).

note that inserting only works when the cursor is in a math inset, but this is unrelated to my patch

ed.
Index: src/frontends/qt4/iconpalette.C
===================================================================
--- src/frontends/qt4/iconpalette.C     (revision 15972)
+++ src/frontends/qt4/iconpalette.C     (working copy)
@@ -11,53 +11,42 @@
 #include <config.h>
 
 #include "iconpalette.h"
-
-#include "debug.h"
-
 #include "qt_helpers.h"
+#include "controllers/ControlMath.h" // for find_xpm
 
-#include <QVBoxLayout>
 #include <QPixmap>
-#include <QHBoxLayout>
 #include <QGridLayout>
-#include <QResizeEvent>
-#include <QLayout>
 #include <QPushButton>
 #include <QToolTip>
 
-using std::endl;
 using std::make_pair;
-using std::max;
 using std::string;
 using std::vector;
 
 
 namespace lyx {
 
-int const button_size = 32;
+int const button_size = 40;
 
 
-IconPalette::IconPalette(QWidget * parent)
-       : QWidget(parent), maxcol_(-1)
+IconPalette::IconPalette(QWidget * parent, char const ** entries)
+       : QWidget(parent)
 {
-       QVBoxLayout * top = new QVBoxLayout(this);
-       QHBoxLayout * row = new QHBoxLayout(this);
        layout_ = new QGridLayout(this);
-       top->insertLayout(-1, row);
-       row->insertLayout(-1, layout_);
-       row->addStretch(0);
-       top->addStretch(0);
-}
+       layout_->setSpacing(0);
 
+       for (int i = 0; *entries[i]; ++i) {
+               QPushButton * p = new QPushButton;
+               p->setFixedSize(button_size, button_size);
+               
p->setIcon(QPixmap(toqstr(lyx::frontend::find_xpm(entries[i]))));
+               p->setToolTip(toqstr(string("\\") + entries[i]));
+               connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
+               buttons_.push_back(make_pair(p, entries[i]));
+               // put in a grid layout with 6 cols
+               int const row = i/5;
+               layout_->addWidget(p, row, i - 5*row);
+       }
 
-void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
-{
-       QPushButton * p = new QPushButton(this);
-       p->setFixedSize(button_size, button_size);
-       p->setIcon(QIcon(pixmap));
-       p->setToolTip(toqstr(tooltip));
-       connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
-       buttons_.push_back(make_pair(p, name));
 }
 
 
@@ -75,79 +64,7 @@
 }
 
 
-void IconPalette::resizeEvent(QResizeEvent * e)
-{
-       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;
-
-       int cols = max(width() / button_size, 1);
-       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
-       int i = 0;
-       QLayoutItem *child;
-       while ((child = layout_->itemAt(i)) != 0) {
-               layout_->takeAt(i);
-               ++i;
-       } 
-
-       layout_->invalidate();
-
-       vector<Button>::const_iterator it(buttons_.begin());
-       vector<Button>::const_iterator const end(buttons_.end());
-
-       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;
-               }
-       }
-
-out:
-
-       int maxrow_ = int(buttons_.size() / cols);
-       if (!maxrow_ || buttons_.size() % cols )
-               ++maxrow_;
-       if(!parent())
-               setMinimumHeight(button_size * maxrow_ + 20); //prevents the 
detached panel becomes unreadable
-       else 
-               resize(cols * button_size, rows * button_size);
-
-       maxcol_ = cols;
-
-       setUpdatesEnabled(true);
-       update();
-}
-
-int IconPalette::numRows() 
-{
-       return maxrow_;
-}
-
-
-int IconPalette::numButtons() 
-{
-       return buttons_.size();
-}
-
-
-
 } // namespace lyx
 
 #include "iconpalette_moc.cpp"
Index: src/frontends/qt4/iconpalette.h
===================================================================
--- src/frontends/qt4/iconpalette.h     (revision 15972)
+++ src/frontends/qt4/iconpalette.h     (working copy)
@@ -22,7 +22,6 @@
 class QPixmap;
 class QPushButton;
 class QGridLayout;
-class QResizeEvent;
 
 namespace lyx {
 
@@ -32,26 +31,14 @@
 class IconPalette : public QWidget {
        Q_OBJECT
 public:
-       IconPalette(QWidget * parent);
+       IconPalette(QWidget * parent, char const ** entries);
 
-       /// add a button
-       void add(QPixmap const & pixmap, std::string name, std::string tooltip);
-       /// get required number of rows.
-       int numRows();
-       /// get number of Buttons
-       int numButtons();
-
 Q_SIGNALS:
        void button_clicked(const std::string &);
-protected:
-       virtual void resizeEvent(QResizeEvent * e);
 protected Q_SLOTS:
        virtual void clicked();
 private:
-       int maxcol_;
 
-       int maxrow_;
-
        QGridLayout * layout_;
 
        typedef std::pair<QPushButton *, std::string> Button;
Index: src/frontends/qt4/QMathDialog.C
===================================================================
--- src/frontends/qt4/QMathDialog.C     (revision 15972)
+++ src/frontends/qt4/QMathDialog.C     (working copy)
@@ -180,10 +180,7 @@
 
 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
 {
-       IconPalette * p = new IconPalette(parent);
-       for (int i = 0; *entries[i]; ++i) {
-               p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], 
string("\\") + entries[i]);
-       }
+       IconPalette * p = new IconPalette(parent, entries);
        // Leave these std:: qualifications alone !
        connect(p, SIGNAL(button_clicked(const std::string &)),
                this, SLOT(symbol_clicked(const std::string &)));
@@ -196,7 +193,6 @@
 {
        QScrollArea * sc = new QScrollArea(symbolWS);
        IconPalette * p = makePanel(this, panels[num]);
-       p->resize(40 * 5, p->height());
        sc->setWidget(p);
        panel_index[num] = symbolWS->addWidget(sc);
 }
@@ -223,16 +219,12 @@
 void QMathDialog::expandClicked()
 {
        int const id = symbolsCO->currentIndex();
-       IconPalette * p = makePanel(0, panels[id]);
-       p->setFixedWidth(40 * 15 + 20);
+       IconPalette * p = makePanel(this, panels[id]);
        string s = "LyX: ";
        s += fromqstr(symbolsCO->currentText());
        p->setWindowTitle(toqstr(s));
-       p->resize(40 * 5, p->height());
+       p->setWindowFlags(Qt::Dialog);
        p->show();
-       p->resize(40 * 5 + 20, 40 * p->numRows() + 20);
-       p->setMinimumSize(40 * 5 + 20, 40 * 1 + 20);
-       p->setMaximumWidth (40 * p->numButtons() + 20);
 }
 
 

Reply via email to