]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiParagraph.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiParagraph.cpp
index 8013464a9d48452cf2558398ad7826b024d73c15..b73a5f53ae7285ae7d48d84720671d1d400f0485 100644 (file)
 
 #include "GuiParagraph.h"
 
+#include "qt_helpers.h"
+
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Cursor.h"
-#include "debug.h"
-//#include "DialogView.h"
-//#include "DockView.h"
-#include "frontend_helpers.h"
 #include "FuncRequest.h"
-#include "gettext.h"
 #include "GuiView.h"
 #include "Lexer.h"
 #include "Paragraph.h"
 #include "ParagraphParameters.h"
-#include "qt_helpers.h"
 #include "Spacing.h"
 
+#include "support/debug.h"
+#include "support/gettext.h"
+
 #include <QCheckBox>
-#include <QCloseEvent>
 #include <QLineEdit>
 #include <QPushButton>
 
-#include <boost/current_function.hpp>
-
 #include <sstream>
 
-using std::istringstream;
-using std::ostringstream;
-using std::string;
-using std::endl;
+using namespace std;
 
 namespace lyx {
 namespace frontend {
 
-GuiParagraph::GuiParagraph(LyXView & lv)
-       : Dialog(lv)
+GuiParagraph::GuiParagraph(GuiView & lv)
+       : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
 {
        setupUi(this);
-       setWindowTitle(qt_("Paragraph Settings"));
-
-       //setModal(modal);
-       QGridLayout * gridLayout = new QGridLayout(this);
-       gridLayout->setMargin(0);
-       gridLayout->addWidget(this);
 
        connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
        connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
@@ -72,12 +59,20 @@ GuiParagraph::GuiParagraph(LyXView & lv)
        connect(labelWidth, SIGNAL(textChanged(QString)),
                this, SLOT(changed()));
 
-
+#ifdef Q_WS_MACX
+       // On Mac it's common to have tool windows which are always in the
+       // foreground and are hidden when the main window is not focused.
+       setWindowFlags(Qt::Tool);
+       synchronizedViewCB->setChecked(true);
+       closePB->setText(qt_("&Cancel"));
+#else
        synchronizedViewCB->setChecked(false);
+#endif
+
        on_synchronizedViewCB_toggled();
        linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
 
-       labelWidth->setWhatsThis( qt_(
+       labelWidth->setWhatsThis(qt_(
                "As described in the User Guide, the width of"
                " this text determines the width of the label part"
                " of each item in environments like List and"
@@ -88,18 +83,13 @@ GuiParagraph::GuiParagraph(LyXView & lv)
                " items is used."
        ));
 
-       radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
-       radioMap[LYX_ALIGN_BLOCK]  = alignJustRB;
-       radioMap[LYX_ALIGN_LEFT]   = alignLeftRB;
-       radioMap[LYX_ALIGN_RIGHT]  = alignRightRB;
-       radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
-
-       labelMap[LYX_ALIGN_BLOCK]  = _("Justified");
-       labelMap[LYX_ALIGN_LEFT]   = _("Left");
-       labelMap[LYX_ALIGN_RIGHT]  = _("Right");
-       labelMap[LYX_ALIGN_CENTER] = _("Center");
+       radioMap_[LYX_ALIGN_LAYOUT] = alignDefaultRB;
+       radioMap_[LYX_ALIGN_BLOCK]  = alignJustRB;
+       radioMap_[LYX_ALIGN_LEFT]   = alignLeftRB;
+       radioMap_[LYX_ALIGN_RIGHT]  = alignRightRB;
+       radioMap_[LYX_ALIGN_CENTER] = alignCenterRB;
 
-       const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
+       alignDefaultLabel_ = alignDefaultRB->text();
 }
 
 
@@ -111,25 +101,31 @@ void GuiParagraph::on_linespacing_activated(int index)
 
 void GuiParagraph::checkAlignmentRadioButtons()
 {
-       RadioMap::iterator it = radioMap.begin();
-       for (; it != radioMap.end(); ++it) {
+       static std::map<LyXAlignment, QString> labelMap_;
+       if (labelMap_.empty()) {
+               labelMap_[LYX_ALIGN_BLOCK]  = qt_("Justified");
+               labelMap_[LYX_ALIGN_LEFT]   = qt_("Left");
+               labelMap_[LYX_ALIGN_RIGHT]  = qt_("Right");
+               labelMap_[LYX_ALIGN_CENTER] = qt_("Center");
+       }
+
+       RadioMap::iterator it = radioMap_.begin();
+       for (; it != radioMap_.end(); ++it) {
                LyXAlignment const align = it->first;
                it->second->setEnabled(align & alignPossible());
        }
-       if (haveMulitParSelection())
-               alignDefaultRB->setText(alignDefaultLabel);
+       if (haveMultiParSelection())
+               alignDefaultRB->setText(alignDefaultLabel_);
        else
-               alignDefaultRB->setText(alignDefaultLabel + " ("
-                       + toqstr(labelMap[alignDefault()]) + ")");
+               alignDefaultRB->setText(alignDefaultLabel_ + " ("
+                       + labelMap_[alignDefault()] + ")");
 }
 
 
 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
 {
-       RadioMap::const_iterator it = radioMap.begin();
-       for (;it != radioMap.end(); ++it) {
-               if (!it->second->isEnabled())
-                       continue;
+       RadioMap::const_iterator it = radioMap_.begin();
+       for (;it != radioMap_.end(); ++it) {
                it->second->blockSignals(true);
                it->second->setChecked(align == it->first);
                it->second->blockSignals(false);
@@ -140,8 +136,8 @@ void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
 LyXAlignment GuiParagraph::getAlignmentFromDialog()
 {
        LyXAlignment alignment = LYX_ALIGN_NONE;
-       RadioMap::const_iterator it = radioMap.begin();
-       for (; it != radioMap.end(); ++it) {
+       RadioMap::const_iterator it = radioMap_.begin();
+       for (; it != radioMap_.end(); ++it) {
                if (it->second->isChecked()) {
                        alignment = it->first;
                        break;
@@ -156,6 +152,11 @@ void GuiParagraph::on_synchronizedViewCB_toggled()
        bool in_sync = synchronizedViewCB->isChecked();
        restorePB->setEnabled(!in_sync);
        applyPB->setEnabled(!in_sync);
+       okPB->setEnabled(!in_sync);
+       if (!in_sync)
+               closePB->setText(qt_("&Cancel"));
+       else
+               closePB->setText(qt_("&Close"));
 }
 
 
@@ -167,6 +168,31 @@ void GuiParagraph::changed()
 
 
 void GuiParagraph::on_applyPB_clicked()
+{
+       applyView();
+}
+
+
+void GuiParagraph::on_okPB_clicked()
+{
+       applyView();
+       hide();
+}
+
+
+void GuiParagraph::on_closePB_clicked()
+{
+       hide();
+}
+
+
+void GuiParagraph::on_restorePB_clicked()
+{
+       updateView();
+}
+
+
+void GuiParagraph::applyView()
 {
        ParagraphParameters & pp = params();
 
@@ -206,12 +232,6 @@ void GuiParagraph::on_applyPB_clicked()
 }
 
 
-void GuiParagraph::on_restorePB_clicked()
-{
-       updateView();
-}
-
-
 void GuiParagraph::updateView()
 {
        on_synchronizedViewCB_toggled();
@@ -226,7 +246,7 @@ void GuiParagraph::updateView()
                labelWidth->setText(toqstr(labelwidth));
        } else {
                labelwidthGB->setEnabled(false);
-               labelWidth->setText("");
+               labelWidth->setText(QString());
        }
 
        // alignment
@@ -269,9 +289,25 @@ void GuiParagraph::updateView()
 }
 
 
+void GuiParagraph::enableView(bool enable)
+{
+       indentCB->setEnabled(enable);
+       linespacing->setEnabled(enable);
+       labelWidth->setEnabled(enable);
+       synchronizedViewCB->setEnabled(enable);
+       applyPB->setEnabled(enable);
+       restorePB->setEnabled(enable);
+       if (!enable)
+               synchronizedViewCB->setChecked(true);
+       RadioMap::const_iterator it = radioMap_.begin();
+       for (; it != radioMap_.end(); ++it)
+               it->second->setEnabled(enable);
+}
+
+
 ParagraphParameters & GuiParagraph::params()
 {
-       if (haveMulitParSelection()) {
+       if (haveMultiParSelection()) {
                multiparsel_ = ParagraphParameters();
                // FIXME: It would be nice to initialise the parameters that
                // are common to all paragraphs.
@@ -290,20 +326,20 @@ ParagraphParameters const & GuiParagraph::params() const
 
 void GuiParagraph::dispatchParams()
 {
-       if (haveMulitParSelection()) {
+       if (haveMultiParSelection()) {
                ostringstream data;
                multiparsel_.write(data);
-               FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
+               FuncRequest const fr(getLfun(), data.str());
                dispatch(fr);
                return;
        }
 
-       bufferview()->updateMetrics(false);
+       bufferview()->updateMetrics();
        bufferview()->buffer().changed();
 }
 
 
-bool GuiParagraph::haveMulitParSelection()
+bool GuiParagraph::haveMultiParSelection()
 {
        Cursor cur = bufferview()->cursor();
        return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
@@ -312,35 +348,25 @@ bool GuiParagraph::haveMulitParSelection()
        
 bool GuiParagraph::canIndent() const
 {
-       return buffer().params().paragraph_separation ==
-               BufferParams::PARSEP_INDENT;
+       return buffer().params().paragraph_separation
+               == BufferParams::ParagraphIndentSeparation;
 }
 
 
 LyXAlignment GuiParagraph::alignPossible() const
 {
-       return bufferview()->cursor().innerParagraph().layout()->alignpossible;
+       return bufferview()->cursor().innerParagraph().layout().alignpossible;
 }
 
 
 LyXAlignment GuiParagraph::alignDefault() const
 {
-       return bufferview()->cursor().innerParagraph().layout()->align;
+       return bufferview()->cursor().innerParagraph().layout().align;
 }
 
 
-Dialog * createGuiParagraph(LyXView & lv)
+Dialog * createGuiParagraph(GuiView & lv)
 {
-#if 0
-       GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
-#ifdef USE_DOCK_WIDGET
-       return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
-               Qt::TopDockWidgetArea);
-#else
-       return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
-#endif
-#endif
-
        return new GuiParagraph(lv);
 }