]> git.lyx.org Git - features.git/commitdiff
* show symbol panels in proper size when detached from math panel (always layed out...
authorEdwin Leuven <e.leuven@gmail.com>
Sun, 19 Nov 2006 17:12:33 +0000 (17:12 +0000)
committerEdwin Leuven <e.leuven@gmail.com>
Sun, 19 Nov 2006 17:12:33 +0000 (17:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15988 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/QMathDialog.C
src/frontends/qt4/QMathDialog.h
src/frontends/qt4/iconpalette.C
src/frontends/qt4/iconpalette.h

index 3ae10fdd809c4c6dc48039bbac1227ad7c2d8ca2..fc0a30be491ae618c0f690f256beff07ae533018 100644 (file)
@@ -14,7 +14,6 @@
 #include "QMath.h"
 
 #include <QPixmap>
-#include <QResizeEvent>
 #include <QScrollArea>
 #include <QMenu>
 #include <QPushButton>
@@ -98,11 +97,8 @@ QMathDialog::QMathDialog(QMath * form)
        }
        //functionsLW->setFixedWidth(functionsLW->sizeHint().width());
 
-       // add first symbol panel
-       addPanel(0);
+       // show first symbol panel
        showingPanel(0);
-       // 5 buttons + 2 margins + 1 scrollbar
-       symbolWS->setFixedWidth(5*40 + 2*10 + 15 );
 
        // add menu's to the buttons
        QMenu * m = new QMenu(spacePB);
@@ -180,10 +176,7 @@ void QMathDialog::showingPanel(int num)
 
 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 +189,6 @@ void QMathDialog::addPanel(int num)
 {
        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 +215,12 @@ void QMathDialog::delimiterClicked()
 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);
 }
 
 
index 93b2959a86274d8635582554e9b17a4ab4d5b8df..d590607fe546d26bca7b51224492461acdca61a8 100644 (file)
 class QListWidgetItem;
 
 namespace lyx {
+namespace frontend {
 
 class IconPalette;
 
-namespace frontend {
-
 class QMAction : public QAction {
        Q_OBJECT
 public:
index f18a90964508f8bbd5d17219bd503667f3a78e24..867f9f210c1cf0608151cf58bd4e5b63ed232c6c 100644 (file)
 #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 {
+namespace frontend {
 
-int const button_size = 32;
-
-
-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);
-}
-
+       QGridLayout * layout_ = new QGridLayout(this);
+       layout_->setSpacing(0);
+
+       int const button_size = 40;
+       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 5 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 +63,7 @@ void IconPalette::clicked()
 }
 
 
-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 frontend
 } // namespace lyx
 
 #include "iconpalette_moc.cpp"
index b4d247d85db4a6b0a63296a8d18323e5e1c4d05e..49c02dfc0be8f9ccd9f8c28979c1c5265f0e02be 100644 (file)
 #include <utility>
 #include <vector>
 
-
-class QPixmap;
 class QPushButton;
-class QGridLayout;
-class QResizeEvent;
 
 namespace lyx {
+namespace frontend {
 
 /**
  * For holding an arbitrary set of icons.
@@ -32,34 +29,21 @@ namespace lyx {
 class IconPalette : public QWidget {
        Q_OBJECT
 public:
-       IconPalette(QWidget * parent);
-
-       /// 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();
+       IconPalette(QWidget * parent, char const ** entries);
 
 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_;
 
+private:
        typedef std::pair<QPushButton *, std::string> Button;
-
        std::vector<Button> buttons_;
 };
 
 
+} // namespace frontend
 } // namespace lyx
 
 #endif // ICONPALETTE_H