Exemple #1
0
void TextTools::indentMoreClicked()
      {
      QTextList* list = cursor()->currentList();
      if (list == 0) {
            QTextBlockFormat format = cursor()->blockFormat();
            format.setIndent(format.indent() + 1);
            cursor()->insertBlock(format);
            updateText();
            return;
            }
      unorderedListClicked();
      }
TextTools::TextTools(QWidget* parent)
   : QDockWidget(parent)
      {
      _textElement = 0;
      setObjectName("text-tools");
      setWindowTitle(tr("Text Tools"));
      setAllowedAreas(Qt::DockWidgetAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea));

      QToolBar* tb = new QToolBar(tr("Text Edit"));
      tb->setIconSize(QSize(preferences.iconWidth, preferences.iconHeight));

      textStyles = new QComboBox;
      tb->addWidget(textStyles);

      showKeyboard = getAction("show-keys");
      showKeyboard->setCheckable(true);
      tb->addAction(showKeyboard);

      typefaceBold = tb->addAction(*icons[textBold_ICON], "");
      typefaceBold->setToolTip(tr("bold"));
      typefaceBold->setCheckable(true);

      typefaceItalic = tb->addAction(*icons[textItalic_ICON], "");
      typefaceItalic->setToolTip(tr("italic"));
      typefaceItalic->setCheckable(true);

      typefaceUnderline = tb->addAction(*icons[textUnderline_ICON], "");
      typefaceUnderline->setToolTip(tr("underline"));
      typefaceUnderline->setCheckable(true);

      tb->addSeparator();

      QActionGroup* ha = new QActionGroup(tb);
      leftAlign   = new QAction(*icons[textLeft_ICON],   "", ha);
      leftAlign->setToolTip(tr("align left"));
      leftAlign->setCheckable(true);
      leftAlign->setData(ALIGN_LEFT);
      hcenterAlign = new QAction(*icons[textCenter_ICON], "", ha);
      hcenterAlign->setToolTip(tr("align horizontal center"));
      hcenterAlign->setCheckable(true);
      hcenterAlign->setData(ALIGN_HCENTER);
      rightAlign  = new QAction(*icons[textRight_ICON],  "", ha);
      rightAlign->setToolTip(tr("align right"));
      rightAlign->setCheckable(true);
      rightAlign->setData(ALIGN_RIGHT);
      tb->addActions(ha->actions());

      QActionGroup* va = new QActionGroup(tb);
      topAlign  = new QAction(*icons[textTop_ICON],  "", va);
      topAlign->setToolTip(tr("align top"));
      topAlign->setCheckable(true);
      topAlign->setData(ALIGN_TOP);

      bottomAlign  = new QAction(*icons[textBottom_ICON],  "", va);
      bottomAlign->setToolTip(tr("align bottom"));
      bottomAlign->setCheckable(true);
      bottomAlign->setData(ALIGN_BOTTOM);

      baselineAlign  = new QAction(*icons[textBaseline_ICON],  "", va);
      baselineAlign->setToolTip(tr("align vertical baseline"));
      baselineAlign->setCheckable(true);
      baselineAlign->setData(ALIGN_BASELINE);

      vcenterAlign  = new QAction(*icons[textVCenter_ICON],  "", va);
      vcenterAlign->setToolTip(tr("align vertical center"));
      vcenterAlign->setCheckable(true);
      vcenterAlign->setData(ALIGN_VCENTER);
      tb->addActions(va->actions());

      typefaceSubscript   = tb->addAction(*icons[textSub_ICON], "");
      typefaceSubscript->setToolTip(tr("subscript"));
      typefaceSubscript->setCheckable(true);

      typefaceSuperscript = tb->addAction(*icons[textSuper_ICON], "");
      typefaceSuperscript->setToolTip(tr("superscript"));
      typefaceSuperscript->setCheckable(true);

      unorderedList = tb->addAction(*icons[formatListUnordered_ICON], "");
      unorderedList->setToolTip(tr("unordered list"));

      orderedList = tb->addAction(*icons[formatListOrdered_ICON], "");
      orderedList->setToolTip(tr("ordered list"));

      indentMore = tb->addAction(*icons[formatIndentMore_ICON], "");
      indentMore->setToolTip(tr("indent more"));

      indentLess = tb->addAction(*icons[formatIndentLess_ICON], "");
      indentLess->setToolTip(tr("indent less"));

      tb->addSeparator();

      typefaceFamily = new QFontComboBox(this);
      tb->addWidget(typefaceFamily);
      typefaceSize = new QDoubleSpinBox(this);
      tb->addWidget(typefaceSize);

      setWidget(tb);
      QWidget* w = new QWidget(this);
      setTitleBarWidget(w);
      titleBarWidget()->hide();

      connect(typefaceSize,        SIGNAL(valueChanged(double)), SLOT(sizeChanged(double)));
      connect(typefaceFamily,      SIGNAL(currentFontChanged(const QFont&)), SLOT(fontChanged(const QFont&)));
      connect(typefaceBold,        SIGNAL(triggered(bool)), SLOT(boldClicked(bool)));
      connect(typefaceItalic,      SIGNAL(triggered(bool)), SLOT(italicClicked(bool)));
      connect(typefaceUnderline,   SIGNAL(triggered(bool)), SLOT(underlineClicked(bool)));
      connect(typefaceSubscript,   SIGNAL(triggered(bool)), SLOT(subscriptClicked(bool)));
      connect(typefaceSuperscript, SIGNAL(triggered(bool)), SLOT(superscriptClicked(bool)));
      connect(typefaceFamily,      SIGNAL(currentFontChanged(const QFont&)), SLOT(fontChanged(const QFont&)));
      connect(ha,                  SIGNAL(triggered(QAction*)), SLOT(setHalign(QAction*)));
      connect(va,                  SIGNAL(triggered(QAction*)), SLOT(setValign(QAction*)));
      connect(showKeyboard,        SIGNAL(triggered(bool)), SLOT(showKeyboardClicked(bool)));
      connect(textStyles,          SIGNAL(currentIndexChanged(int)), SLOT(styleChanged(int)));
      connect(unorderedList,       SIGNAL(triggered()),     SLOT(unorderedListClicked()));
      connect(orderedList,         SIGNAL(triggered()),     SLOT(orderedListClicked()));
      connect(indentLess,          SIGNAL(triggered()),     SLOT(indentLessClicked()));
      connect(indentMore,          SIGNAL(triggered()),     SLOT(indentMoreClicked()));
      }