From 17bf0023c75908cdd477a7738c9766e3e31ed465 Mon Sep 17 00:00:00 2001 From: Edwin Leuven Date: Sun, 19 Nov 2006 17:12:33 +0000 Subject: [PATCH] * show symbol panels in proper size when detached from math panel (always layed out in 5 cols) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15988 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/QMathDialog.C | 20 ++---- src/frontends/qt4/QMathDialog.h | 3 +- src/frontends/qt4/iconpalette.C | 122 +++++--------------------------- src/frontends/qt4/iconpalette.h | 26 ++----- 4 files changed, 29 insertions(+), 142 deletions(-) diff --git a/src/frontends/qt4/QMathDialog.C b/src/frontends/qt4/QMathDialog.C index 3ae10fdd80..fc0a30be49 100644 --- a/src/frontends/qt4/QMathDialog.C +++ b/src/frontends/qt4/QMathDialog.C @@ -14,7 +14,6 @@ #include "QMath.h" #include -#include #include #include #include @@ -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); } diff --git a/src/frontends/qt4/QMathDialog.h b/src/frontends/qt4/QMathDialog.h index 93b2959a86..d590607fe5 100644 --- a/src/frontends/qt4/QMathDialog.h +++ b/src/frontends/qt4/QMathDialog.h @@ -20,11 +20,10 @@ class QListWidgetItem; namespace lyx { +namespace frontend { class IconPalette; -namespace frontend { - class QMAction : public QAction { Q_OBJECT public: diff --git a/src/frontends/qt4/iconpalette.C b/src/frontends/qt4/iconpalette.C index f18a909645..867f9f210c 100644 --- a/src/frontends/qt4/iconpalette.C +++ b/src/frontends/qt4/iconpalette.C @@ -11,53 +11,41 @@ #include #include "iconpalette.h" - -#include "debug.h" - #include "qt_helpers.h" +#include "controllers/ControlMath.h" // for find_xpm -#include #include -#include #include -#include -#include #include #include -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