From: Abdelrazak Younes Date: Wed, 5 Apr 2006 15:10:34 +0000 (+0000) Subject: Porting work from Edwin Leuven: X-Git-Tag: 1.6.10~13404 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ed6eb3e4f24fccf4ca6e363052c2e6f1cf6fd044;p=lyx.git Porting work from Edwin Leuven: * QMathUi.ui: Port to Qt4, icons paths are hacked to point to ../lib/images/ * QMathDialog: Port to qt4 * iconpalette.C: fix cols calculation git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13557 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/QMathDialog.C b/src/frontends/qt4/QMathDialog.C index 2353de891e..04150b8940 100644 --- a/src/frontends/qt4/QMathDialog.C +++ b/src/frontends/qt4/QMathDialog.C @@ -12,57 +12,26 @@ #include "QMathDialog.h" #include "QMath.h" -//Added by qt3to4: + #include #include +#include +#include +#include +#include +#include +#include #include "iconpalette.h" #include "qt_helpers.h" - #include "controllers/ControlMath.h" - #include "frontends/lyx_gui.h" -#include -#include -#include -#include - using std::string; namespace lyx { namespace frontend { -class QScrollViewSingle : public Q3ScrollView { -public: - QScrollViewSingle(QWidget * p) - : Q3ScrollView(p), w_(0) { - setResizePolicy(Manual); - setHScrollBarMode(AlwaysOff); - setVScrollBarMode(AlwaysOn); - setBackgroundMode(Qt::PaletteBackground); - viewport()->setBackgroundMode(Qt::PaletteBackground); - } - - void setChild(QWidget * w) { - w_ = w; - setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4); - addChild(w_); - } -protected: - virtual void resizeEvent(QResizeEvent * e) { - Q3ScrollView::resizeEvent(e); - if (!w_) - return; - - w_->resize(viewport()->width(), w_->height()); - // force the resize to get accurate scrollbar - lyx_gui::sync_events(); - resizeContents(w_->width(), w_->height()); - } -private: - QWidget * w_; -}; namespace { @@ -88,91 +57,89 @@ QMathDialog::QMathDialog(QMath * form) // enlarge the symbols ComboBox (no scrollbar) //symbolsCO->setSizeLimit(13); - connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int))); - - connect( tearoffPB, SIGNAL( clicked() ), this, SLOT( expandClicked() ) ); - connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) ); - connect( fracPB, SIGNAL( clicked() ), this, SLOT( fracClicked() ) ); - connect( superscriptPB, SIGNAL( clicked() ), this, SLOT( superscriptClicked() ) ); - connect( subscriptPB, SIGNAL( clicked() ), this, SLOT( subscriptClicked() ) ); - connect( delimitersPB, SIGNAL( clicked() ), this, SLOT( delimiterClicked() ) ); - connect( matrixPB, SIGNAL( clicked() ), this, SLOT( matrixClicked() ) ); - connect( functionsLB, SIGNAL( selected(const QString&) ), this, SLOT( functionSelected(const QString &) ) ); - connect( equationPB, SIGNAL( clicked() ), this, SLOT( equationClicked() ) ); - + connect( tearoffPB, SIGNAL( clicked() ), this, SLOT( expandClicked() ) ); + connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( fracPB, SIGNAL( clicked() ), this, SLOT( fracClicked() ) ); + connect( superscriptPB, SIGNAL( clicked() ), this, SLOT( superscriptClicked() ) ); + connect( subscriptPB, SIGNAL( clicked() ), this, SLOT( subscriptClicked() ) ); + connect( delimitersPB, SIGNAL( clicked() ), this, SLOT( delimiterClicked() ) ); + connect( matrixPB, SIGNAL( clicked() ), this, SLOT( matrixClicked() ) ); + connect( functionsLW, SIGNAL( itemActivated(QListWidgetItem *) ), this, SLOT( functionSelected(QListWidgetItem *) ) ); + connect( equationPB, SIGNAL( clicked() ), this, SLOT( equationClicked() ) ); + connect( symbolsCO, SIGNAL(activated(int)), this, SLOT(showingPanel(int))); + + // function list for (int i = 0; *function_names[i]; ++i) { - functionsLB->insertItem(function_names[i]); - } - - for (int i = 0; i < nr_panels; ++i) { - QScrollViewSingle * view = new QScrollViewSingle(symbolsWS); - symbolsWS->addWidget(view, i); + functionsLW->addItem(function_names[i]); } + functionsLW->setFixedWidth(functionsLW->sizeHint().width()); - // aboutToShow() only fires when != 0 in Qt 2 ! - symbolsWS->raiseWidget(0); + // add first symbol panel addPanel(0); - panel_initialised[0] = true; - - connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int))); - - Q3PopupMenu * m = new Q3PopupMenu(spacePB); - m->setCaption(qt_("LyX: Math Spacing")); - m->insertTearOffHandle(); - m->insertItem(qt_("Thin space \\,"), 1); - m->insertItem(qt_("Medium space \\:"), 2); - m->insertItem(qt_("Thick space \\;"), 3); - m->insertItem(qt_("Quadratin space \\quad"), 4); - m->insertItem(qt_("Double quadratin space \\qquad"), 5); - m->insertItem(qt_("Negative space \\!"), 6); - connect(m, SIGNAL(activated(int)), this, SLOT(insertSpace(int))); - spacePB->setPopup(m); - - m = new Q3PopupMenu(sqrtPB); - m->setCaption(qt_("LyX: Math Roots")); - m->insertTearOffHandle(); - m->insertItem(qt_("Square root \\sqrt"), 1); - m->insertItem(qt_("Cube root \\root"), 2); - m->insertItem(qt_("Other root \\root"), 3); - connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int))); + 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); + m->setTitle(qt_("LyX: Math Spacing")); + m->setTearOffEnabled(true); + addMenuItem(m, qt_("Thin space \\,"), ","); + addMenuItem(m, qt_("Medium space \\:"), ":"); + addMenuItem(m, qt_("Thick space \\;"), ";"); + addMenuItem(m, qt_("Quadratin space \\quad"), "quad"); + addMenuItem(m, qt_("Double quadratin space \\qquad"), "qquad"); + addMenuItem(m, qt_("Negative space \\!"), "!"); + spacePB->setMenu(m); + + m = new QMenu(sqrtPB); + m->setTitle(qt_("LyX: Math Roots")); + m->setTearOffEnabled(true); + addMenuItem(m, qt_("Square root \\sqrt"), "sqrt"); + QAction * ma = new QAction(qt_("Cube root \\root"), this); + connect(ma, SIGNAL(triggered()), this, SLOT(insertCubeRoot())); + m->addAction(ma); + addMenuItem(m, qt_("Other root \\root"), "root"); sqrtPB->setPopup(m); - m = new Q3PopupMenu(stylePB); - m->setCaption(qt_("LyX: Math Styles")); - m->insertTearOffHandle(); - m->insertItem(qt_("Display style \\displaystyle"), 1); - m->insertItem(qt_("Normal text style \\textstyle"), 2); - m->insertItem(qt_("Script (small) style \\scriptstyle"), 3); - m->insertItem(qt_("Scriptscript (smaller) style \\scriptscriptstyle"), 4); - connect(m, SIGNAL(activated(int)), this, SLOT(insertStyle(int))); + m = new QMenu(stylePB); + m->setTitle(qt_("LyX: Math Styles")); + m->setTearOffEnabled(true); + addMenuItem(m, qt_("Display style \\displaystyle"), "displaystyle"); + addMenuItem(m, qt_("Normal text style \\textstyle"), "textstyle"); + addMenuItem(m, qt_("Script (small) style \\scriptstyle"), "scriptstyle"); + addMenuItem(m, qt_("Scriptscript (smaller) style \\scriptscriptstyle"), "scriptscriptstyle"); stylePB->setPopup(m); - m = new Q3PopupMenu(fontPB); - m->setCaption(qt_("LyX: Math Fonts")); - m->insertTearOffHandle(); - m->insertItem(qt_("Roman \\mathrm"), 1); - m->insertItem(qt_("Bold \\mathbf"), 2); - m->insertItem(qt_("Bold symbol \\boldsymbol"), 3); - m->insertItem(qt_("Sans serif \\mathsf"), 4); - m->insertItem(qt_("Italic \\mathit"), 5); - m->insertItem(qt_("Typewriter \\mathtt"), 6); - m->insertItem(qt_("Blackboard \\mathbb"), 7); - m->insertItem(qt_("Fraktur \\mathfrak"), 8); - m->insertItem(qt_("Calligraphic \\mathcal"), 9); - m->insertItem(qt_("Normal text mode \\textrm"), 10); - connect(m, SIGNAL(activated(int)), this, SLOT(insertFont(int))); + m = new QMenu(fontPB); + m->setTitle(qt_("LyX: Math Fonts")); + m->setTearOffEnabled(true); + addMenuItem(m, qt_("Roman \\mathrm"), "mathrm"); + addMenuItem(m, qt_("Bold \\mathbf"), "mathbf"); + addMenuItem(m, qt_("Bold symbol \\boldsymbol"), "boldsymbol"); + addMenuItem(m, qt_("Sans serif \\mathsf"), "mathsf"); + addMenuItem(m, qt_("Italic \\mathit"), "mathit"); + addMenuItem(m, qt_("Typewriter \\mathtt"), "mathtt"); + addMenuItem(m, qt_("Blackboard \\mathbb"), "mathbb"); + addMenuItem(m, qt_("Fraktur \\mathfrak"), "mathfrak"); + addMenuItem(m, qt_("Calligraphic \\mathcal"), "mathcal"); + addMenuItem(m, qt_("Normal text mode \\textrm"), "textrm"); fontPB->setPopup(m); } +void QMathDialog::addMenuItem(QMenu * menu, const QString & label, const std::string & action) +{ + QMAction * ma = new QMAction(label,action, this); + connect(ma, SIGNAL(action(const std::string &)), this, SLOT(symbol_clicked(const std::string &))); + menu->addAction(ma); +} void QMathDialog::showingPanel(int num) { - if (panel_initialised[num]) - return; + if (!panel_initialised[num]) + addPanel(num); - addPanel(num); - - panel_initialised[num] = true; + symbolWS->setCurrentIndex(num); } @@ -192,9 +159,12 @@ IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries) void QMathDialog::addPanel(int num) { - QScrollViewSingle * view = static_cast(symbolsWS->widget(num)); - IconPalette * p = makePanel(view->viewport(), panels[num]); - view->setChild(p); + QScrollArea * sc = new QScrollArea(symbolWS); + IconPalette * p = makePanel(this, panels[num]); + p->resize(40 * 5, p->height()); + sc->setWidget(p); + symbolWS->insertWidget(num,sc); + panel_initialised[num] = true; } @@ -218,10 +188,10 @@ void QMathDialog::delimiterClicked() void QMathDialog::expandClicked() { - int const id = symbolsWS->id(symbolsWS->visibleWidget()); + int const id = symbolsCO->currentIndex(); IconPalette * p = makePanel(0, panels[id]); string s = "LyX: "; - s += fromqstr(symbolsCO->text(id)); + s += fromqstr(symbolsCO->currentText()); p->setCaption(toqstr(s)); p->resize(40 * 5, p->height()); p->show(); @@ -229,9 +199,9 @@ void QMathDialog::expandClicked() } -void QMathDialog::functionSelected(const QString & str) +void QMathDialog::functionSelected(QListWidgetItem * item) { - form_->controller().dispatchInsert(fromqstr(str)); + form_->controller().dispatchInsert(fromqstr(item->text())); } @@ -259,70 +229,11 @@ void QMathDialog::superscriptClicked() } -void QMathDialog::insertSpace(int id) +void QMathDialog::insertCubeRoot() { - string str; - switch (id) { - case 1: str = ","; break; - case 2: str = ":"; break; - case 3: str = ";"; break; - case 4: str = "quad"; break; - case 5: str = "qquad"; break; - case 6: str = "!"; break; - default: return; - } - form_->controller().dispatchInsert(str); -} - - -void QMathDialog::insertRoot(int id) -{ - switch (id) { - case 1: - form_->controller().dispatchInsert("sqrt"); - break; - case 2: - form_->controller().dispatchCubeRoot(); - break; - case 3: - form_->controller().dispatchInsert("root"); - break; - } -} - - -void QMathDialog::insertStyle(int id) -{ - string str; - switch (id) { - case 1: str = "displaystyle"; break; - case 2: str = "textstyle"; break; - case 3: str = "scriptstyle"; break; - case 4: str = "scriptscriptstyle"; break; - default: return; - } - form_->controller().dispatchInsert(str); + form_->controller().dispatchCubeRoot(); } -void QMathDialog::insertFont(int id) -{ - string str; - switch (id) { - case 1: str = "mathrm"; break; - case 2: str = "mathbf"; break; - case 3: str = "boldsymbol"; break; - case 4: str = "mathsf"; break; - case 5: str = "mathit"; break; - case 6: str = "mathtt"; break; - case 7: str = "mathbb"; break; - case 8: str = "mathfrak"; break; - case 9: str = "mathcal"; break; - case 10: str = "textrm"; break; - default: return; - } - form_->controller().dispatchInsert(str); -} - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/QMathDialog.h b/src/frontends/qt4/QMathDialog.h index 2004a91421..1a49f572ef 100644 --- a/src/frontends/qt4/QMathDialog.h +++ b/src/frontends/qt4/QMathDialog.h @@ -18,10 +18,29 @@ #include class IconPalette; +class QListWidgetItem; namespace lyx { namespace frontend { +class QMAction : public QAction { + Q_OBJECT +public: + QMAction( const QString & text, const std::string & action, QObject * parent) + : QAction(text,parent), action_(action) { + connect(this, SIGNAL(triggered()), this, SLOT(action())); + } +signals: + void action(const std::string &); +protected slots: + void action() { + emit action(action_); + } +private: + std::string action_; +}; + + class QMath; class QMathDialog : public QDialog, public Ui::QMathUi @@ -33,25 +52,23 @@ public slots: virtual void delimiterClicked(); virtual void expandClicked(); virtual void fracClicked(); - virtual void functionSelected(const QString &); + virtual void functionSelected(QListWidgetItem *); virtual void matrixClicked(); virtual void subscriptClicked(); virtual void superscriptClicked(); virtual void equationClicked(); void symbol_clicked(const std::string &); - void insertSpace(int id); - void insertRoot(int id); - void insertStyle(int id); - void insertFont(int id); + void insertCubeRoot(); /// about to show a symbol panel void showingPanel(int); protected: //needed ? virtual void closeEvent(QCloseEvent * e); private: + /// add item to popup menu + void addMenuItem(QMenu * menu, const QString & label, const std::string &); /// make a symbol panel IconPalette * makePanel(QWidget * parent, char const ** entries); - /// add a symbol panel void addPanel(int num); diff --git a/src/frontends/qt4/iconpalette.C b/src/frontends/qt4/iconpalette.C index 72eccb139f..32cef52b50 100644 --- a/src/frontends/qt4/iconpalette.C +++ b/src/frontends/qt4/iconpalette.C @@ -82,7 +82,7 @@ void IconPalette::resizeEvent(QResizeEvent * e) if (!layout_->isEmpty() && maxcol == maxcol_) return; - int cols(width() / button_size); + int cols = max(width() / button_size, 1); int rows = max(int(buttons_.size() / cols), 1); if (buttons_.size() % cols) ++rows; diff --git a/src/frontends/qt4/ui/QMathUi.ui b/src/frontends/qt4/ui/QMathUi.ui index 9fc45b9940..b407f69f5f 100644 --- a/src/frontends/qt4/ui/QMathUi.ui +++ b/src/frontends/qt4/ui/QMathUi.ui @@ -8,8 +8,8 @@ 0 0 - 322 - 356 + 375 + 321 @@ -18,15 +18,15 @@ true - + - 11 + 9 6 - - + + 0 @@ -34,7 +34,7 @@ 6 - + 0 @@ -42,461 +42,182 @@ 6 - - - 0 + + + + 3 + 0 + 0 + 0 + - - 6 + + Select a page of symbols - - - Insert root - - - - - - - - + + Operators + - - - Insert spacing - - - - - - - - + + Big operators + - - - Set limits style - - - - - - - - + + Relations + - - - Set math font - - - - - - - - + + Greek + + + + + Arrows + - - - - - - 0 - - - 6 - - - - 0 - - - 6 - - - - - - 1 - 1 - 0 - 0 - - - - Insert fraction - - - - - - - - - - - - - - 1 - 1 - 0 - 0 - - - - Toggle between display and inline mode - - - - - - - - - - - - - Insert matrix - - - - - - - - - - - - - Subscript - - - - - - - - - - - - - Superscript - - - - - - - - - - - - - Show delimiter and bracket dialog - - - - - - - - - - + + Dots + - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - + + Frame decorations + - - - - - - 0 - - - 6 - - - - 0 - - - 6 - - - - - &Functions - - - functionsLB - - - - - - - - 1 - 7 - 0 - 0 - - - - - 100 - 100 - - - - Select a function or operator to insert - - - - + + Miscellaneous + - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - + + AMS operators + - + + + AMS relations + + + + + AMS negated relations + + + + + AMS arrows + + + + + AMS Miscellaneous + + + + + + + + Qt::Horizontal + + + + 16 + 22 + + + - - - - 7 - 3 - 0 - 0 - + + + + + + + + + 0 - - - 0 - 0 - + + 6 + + + + + Open this panel as a separate window + + + &Detach panel + + + + + + + Qt::Horizontal + + + + 81 + 51 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 0 + + + 6 + + + + + &Functions + + + functionsLW + + + + + + + true - - Symbols - - - - 11 - - - 6 - - - - - 0 - - - 6 - - - - - - 3 - 0 - 0 - 0 - - - - Select a page of symbols - - - - Operators - - - - - Big operators - - - - - Relations - - - - - Greek - - - - - Arrows - - - - - Dots - - - - - Frame decorations - - - - - Miscellaneous - - - - - AMS operators - - - - - AMS relations - - - - - AMS negated relations - - - - - AMS arrows - - - - - AMS Miscellaneous - - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 20 - 20 - - - - - - - - - - - 7 - 7 - 0 - 0 - - - - - 0 - 200 - - - - Qt::TabFocus - - - - - - - 0 - - - 6 - - - - - Open this panel as a separate window - - - &Detach panel - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - + 0 @@ -514,8 +235,8 @@ - 20 - 20 + 471 + 28 @@ -529,25 +250,193 @@ + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + 0 + + + 6 + + + + + Show delimiter and bracket dialog + + + + + + ../lib/images/delim.xpm + + + + + + + + 1 + 1 + 0 + 0 + + + + Insert fraction + + + + + + ../lib/images/frac.xpm + + + + + + + Subscript + + + + + + ../lib/images/sub.xpm + + + + + + + + 1 + 1 + 0 + 0 + + + + Toggle between display and inline mode + + + + + + ../lib/images/equation.xpm + + + + + + + Insert spacing + + + + + + ../lib/images/space.xpm + + + + + + + Insert matrix + + + + + + ../lib/images/matrix.xpm + + + + + + + Insert root + + + + + + ../lib/images/sqrt.xpm + + + + + + + Set limits style + + + + + + ../lib/images/style.xpm + + + + + + + Set math font + + + + + + ../lib/images/font.xpm + + + + + + + Superscript + + + + + + ../lib/images/super.xpm + + + + + - - - Q3ListBox - -
q3listbox.h
- 0 - -
- - Q3WidgetStack - -
q3widgetstack.h
- 1 - -
-
+ + symbolsCO + closePB + tearoffPB + delimitersPB + superscriptPB + subscriptPB + matrixPB + equationPB + fracPB + fontPB + stylePB + spacePB + sqrtPB +