Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/dvtextedit.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qlineedit></qlineedit>
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qtoolbar></qtoolbar>
Toshihiro Shimizu 890ddd
#include <qfontcombobox></qfontcombobox>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qtextcursor></qtextcursor>
Toshihiro Shimizu 890ddd
#include <qcolordialog></qcolordialog>
Toshihiro Shimizu 890ddd
#include <qcombobox></qcombobox>
Toshihiro Shimizu 890ddd
#include <qfontdatabase></qfontdatabase>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/colorfield.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
qreal distanceBetweenPointandRect(const QRect &rect, const QPoint &point) {
Shinya Kitaoka 120a6e
  if (rect.contains(point)) return 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  qreal topLeftDistance =
Shinya Kitaoka 120a6e
      sqrt(pow((double)(point.x() - rect.topLeft().x()), 2) +
Shinya Kitaoka 120a6e
           pow((double)(point.y() - rect.topLeft().y()), 2));
Shinya Kitaoka 120a6e
  qreal topRightDistance =
Shinya Kitaoka 120a6e
      sqrt(pow((double)(point.x() - rect.topRight().x()), 2) +
Shinya Kitaoka 120a6e
           pow((double)(point.y() - rect.topRight().y()), 2));
Shinya Kitaoka 120a6e
  qreal bottomLeftDistance =
Shinya Kitaoka 120a6e
      sqrt(pow((double)(point.x() - rect.bottomLeft().x()), 2) +
Shinya Kitaoka 120a6e
           pow((double)(point.y() - rect.bottomLeft().y()), 2));
Shinya Kitaoka 120a6e
  qreal bottomRightDistance =
Shinya Kitaoka 120a6e
      sqrt(pow((double)(point.x() - rect.bottomRight().x()), 2) +
Shinya Kitaoka 120a6e
           pow((double)(point.y() - rect.bottomRight().y()), 2));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  qreal topMax    = qMin(topLeftDistance, topRightDistance);
Shinya Kitaoka 120a6e
  qreal bottomMax = qMin(bottomLeftDistance, bottomRightDistance);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return qMin(topMax, bottomMax);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DvMiniToolBar
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DvMiniToolBar::DvMiniToolBar(QWidget *parent)
Shinya Kitaoka 120a6e
    : QFrame(parent), m_dragPos(0, 0) {
Shinya Kitaoka 120a6e
  setObjectName("DvMiniToolBar");
Shinya Kitaoka 120a6e
  setStyleSheet("#DvMiniToolBar {border: 1px solid black;}");
Shinya Kitaoka 120a6e
  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DvMiniToolBar::~DvMiniToolBar() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvMiniToolBar::mousePressEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  if (e->button() == Qt::LeftButton)
Shinya Kitaoka 120a6e
    m_dragPos = e->globalPos() - frameGeometry().topLeft();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QWidget::mousePressEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvMiniToolBar::mouseMoveEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  if (e->buttons() == Qt::LeftButton) move(e->globalPos() - m_dragPos);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QWidget::mouseMoveEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DvTextEditButton
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DvTextEditButton::DvTextEditButton(QWidget *parent) : QWidget(parent) {
Shinya Kitaoka 120a6e
  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
Shinya Kitaoka 120a6e
  setFixedSize(16, 16);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DvTextEditButton::~DvTextEditButton() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEditButton::paintEvent(QPaintEvent *) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
  static QPixmap pixmap(":Resources/text_edit_button.png");
Shinya Kitaoka 120a6e
  p.drawPixmap(0, 0, width(), height(), pixmap);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEditButton::mousePressEvent(QMouseEvent *) {
Shinya Kitaoka 120a6e
  emit clicked();
Shinya Kitaoka 120a6e
  hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DvTextEdit
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DvTextEdit::DvTextEdit(QWidget *parent)
Shinya Kitaoka 120a6e
    : QTextEdit(parent), m_miniToolBarEnabled(true), m_mousePos(0, 0) {
Shinya Kitaoka 120a6e
  setMouseTracking(true);
Shinya Kitaoka 120a6e
  createActions();
Shinya Kitaoka 120a6e
  createMiniToolBar();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_button = new DvTextEditButton(0);
Shinya Kitaoka 120a6e
  m_button->hide();
Shinya Kitaoka 120a6e
  connect(m_button, SIGNAL(clicked()), this, SLOT(onShowMiniToolBarClicked()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  fontChanged(font());
Shinya Kitaoka 120a6e
  setTextColor(TPixel32::Black, false);
Shinya Kitaoka 120a6e
  alignmentChanged(alignment());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), this,
Shinya Kitaoka 120a6e
          SLOT(onCurrentCharFormatChanged(const QTextCharFormat &)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(this, SIGNAL(cursorPositionChanged()), this,
Shinya Kitaoka 120a6e
          SLOT(onCursorPositionChanged()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void DvTextEdit::changeFont(const QFont &f) {
Shinya Kitaoka 120a6e
  QTextCharFormat fmt = currentCharFormat();
Shinya Kitaoka 120a6e
  // bool aux = fmt.fontUnderline();
Shinya Kitaoka 120a6e
  fmt.setFont(f);
Shinya Kitaoka 120a6e
  // fmt.setFontHintingPreference(QFont::PreferFullHinting);
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DvTextEdit::~DvTextEdit() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::createActions() {
Shinya Kitaoka 120a6e
  m_boldAction = new QAction(createQIconOnOffPNG("bold"), tr("Bold"), this);
Shinya Kitaoka 120a6e
  m_boldAction->setCheckable(true);
Shinya Kitaoka 120a6e
  connect(m_boldAction, SIGNAL(triggered()), this, SLOT(setTextBold()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_italicAction =
Shinya Kitaoka 120a6e
      new QAction(createQIconOnOffPNG("italic"), tr("Italic"), this);
Shinya Kitaoka 120a6e
  m_italicAction->setCheckable(true);
Shinya Kitaoka 120a6e
  connect(m_italicAction, SIGNAL(triggered()), this, SLOT(setTextItalic()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_underlineAction =
Shinya Kitaoka 120a6e
      new QAction(createQIconOnOffPNG("underline"), tr("Underline"), this);
Shinya Kitaoka 120a6e
  m_underlineAction->setCheckable(true);
Shinya Kitaoka 120a6e
  connect(m_underlineAction, SIGNAL(triggered()), this,
Shinya Kitaoka 120a6e
          SLOT(setTextUnderline()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_colorField = new DVGui::ColorField(this, true, TPixel32(), 30);
Shinya Kitaoka 120a6e
  m_colorField->hideChannelsFields(true);
Shinya Kitaoka 120a6e
  connect(m_colorField, SIGNAL(colorChanged(const TPixel32 &, bool)), this,
Shinya Kitaoka 120a6e
          SLOT(setTextColor(const TPixel32 &, bool)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_alignActionGroup = new QActionGroup(this);
Shinya Kitaoka 120a6e
  connect(m_alignActionGroup, SIGNAL(triggered(QAction *)), this,
Shinya Kitaoka 120a6e
          SLOT(setTextAlign(QAction *)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_alignLeftAction = new QAction(createQIconOnOffPNG("align_left"),
Shinya Kitaoka 120a6e
                                  tr("Align Left"), m_alignActionGroup);
Shinya Kitaoka 120a6e
  m_alignLeftAction->setCheckable(true);
Shinya Kitaoka 120a6e
  m_alignCenterAction = new QAction(createQIconOnOffPNG("align_center"),
Shinya Kitaoka 120a6e
                                    tr("Align Center"), m_alignActionGroup);
Shinya Kitaoka 120a6e
  m_alignCenterAction->setCheckable(true);
Shinya Kitaoka 120a6e
  m_alignRightAction = new QAction(createQIconOnOffPNG("align_right"),
Shinya Kitaoka 120a6e
                                   tr("Align Right"), m_alignActionGroup);
Shinya Kitaoka 120a6e
  m_alignRightAction->setCheckable(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::createMiniToolBar() {
Shinya Kitaoka 120a6e
  m_miniToolBar = new DvMiniToolBar();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QToolBar *toolBarUp = new QToolBar(m_miniToolBar);
Shinya Kitaoka 120a6e
  toolBarUp->setIconSize(QSize(30, 30));
Shinya Kitaoka 120a6e
  toolBarUp->setObjectName("toolOptionBar");
Shinya Kitaoka 120a6e
  toolBarUp->setFixedHeight(30);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_fontComboBox = new QFontComboBox(toolBarUp);
Shinya Kitaoka 120a6e
  m_fontComboBox->setMaximumHeight(20);
Shinya Kitaoka 120a6e
  m_fontComboBox->setMinimumWidth(140);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(m_fontComboBox, SIGNAL(activated(const QString &)), this,
Shinya Kitaoka 120a6e
          SLOT(setTextFamily(const QString &)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_sizeComboBox = new QComboBox(toolBarUp);
Shinya Kitaoka 120a6e
  m_sizeComboBox->setEditable(true);
Shinya Kitaoka 120a6e
  m_sizeComboBox->setMaximumHeight(20);
Shinya Kitaoka 120a6e
  m_sizeComboBox->setMinimumWidth(44);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QFontDatabase db;
otakuto dfe1cf
  for (int size : db.standardSizes())
Shinya Kitaoka 120a6e
    m_sizeComboBox->addItem(QString::number(size));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(m_sizeComboBox, SIGNAL(activated(const QString &)), this,
Shinya Kitaoka 120a6e
          SLOT(setTextSize(const QString &)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  toolBarUp->addWidget(m_fontComboBox);
Shinya Kitaoka 120a6e
  toolBarUp->addWidget(m_sizeComboBox);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QToolBar *toolBarDown = new QToolBar(m_miniToolBar);
Shinya Kitaoka 120a6e
  toolBarDown->setIconSize(QSize(30, 30));
Shinya Kitaoka 120a6e
  toolBarDown->setObjectName("toolOptionBar");
Shinya Kitaoka 120a6e
  toolBarDown->setFixedHeight(30);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  toolBarDown->setIconSize(QSize(30, 30));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  toolBarDown->addWidget(m_colorField);
Shinya Kitaoka 120a6e
  toolBarDown->addSeparator();
Shinya Kitaoka 120a6e
  toolBarDown->addAction(m_boldAction);
Shinya Kitaoka 120a6e
  toolBarDown->addAction(m_italicAction);
Shinya Kitaoka 120a6e
  toolBarDown->addAction(m_underlineAction);
Shinya Kitaoka 120a6e
  toolBarDown->addSeparator();
Shinya Kitaoka 120a6e
  toolBarDown->addActions(m_alignActionGroup->actions());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QVBoxLayout *m_mainLayout = new QVBoxLayout(m_miniToolBar);
Shinya Kitaoka 120a6e
  m_mainLayout->setSizeConstraint(QLayout::SetFixedSize);
Shinya Kitaoka 120a6e
  m_mainLayout->setMargin(2);
Shinya Kitaoka 120a6e
  m_mainLayout->setSpacing(2);
Shinya Kitaoka 120a6e
  m_mainLayout->addWidget(toolBarUp);
Shinya Kitaoka 120a6e
  m_mainLayout->addWidget(toolBarDown);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_miniToolBar->setLayout(m_mainLayout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::mouseReleaseEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  QTextEdit::mouseReleaseEvent(e);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (e->button() == Qt::LeftButton && m_miniToolBarEnabled) {
Shinya Kitaoka 120a6e
    QTextCursor cursor = textCursor();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (cursor.hasSelection()) {
Shinya Kitaoka 120a6e
      cursor.setPosition(cursor.selectionEnd(), QTextCursor::MoveAnchor);
Shinya Kitaoka 120a6e
      QRect r          = cursorRect(cursor);
Shinya Kitaoka 120a6e
      QPoint buttonPos = mapToGlobal(r.topRight());
Shinya Kitaoka 120a6e
      buttonPos.setX(buttonPos.x() - r.width() * 0.5 + 2);
Shinya Kitaoka 120a6e
      buttonPos.setY(buttonPos.y() - (m_button->height() - r.height()) * 0.5);
Shinya Kitaoka 120a6e
      m_button->move(buttonPos);
Shinya Kitaoka 120a6e
      m_button->show();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::mousePressEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  QTextEdit::mousePressEvent(e);
Shinya Kitaoka 120a6e
  if (m_miniToolBarEnabled && m_miniToolBar->isVisible()) hideMiniToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::mouseMoveEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  QTextEdit::mouseMoveEvent(event);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_mousePos = event->pos();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::wheelEvent(QWheelEvent *e) {
Shinya Kitaoka 120a6e
  QTextEdit::wheelEvent(e);
Shinya Kitaoka 120a6e
  m_button->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::focusOutEvent(QFocusEvent *e) {
Shinya Kitaoka 120a6e
  QTextEdit::focusOutEvent(e);
Shinya Kitaoka 120a6e
  if (m_miniToolBar->isVisible() && !m_miniToolBar->underMouse()) {
Shinya Kitaoka 120a6e
    hideMiniToolBar();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_button->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::focusInEvent(QFocusEvent *e) {
Shinya Kitaoka 120a6e
  QTextEdit::focusInEvent(e);
Shinya Kitaoka 120a6e
  emit focusIn();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::dragMoveEvent(QDragMoveEvent *e) {
Shinya Kitaoka 120a6e
  // Se inizio un drag e la toolbar รจ visibile la nascondo
Shinya Kitaoka 120a6e
  if (m_miniToolBar->isVisible()) hideMiniToolBar();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_button->hide();
Shinya Kitaoka 120a6e
  QTextEdit::dragMoveEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::showMiniToolBar(const QPoint &pos) {
Shinya Kitaoka 120a6e
  if (m_miniToolBarEnabled) {
Shinya Kitaoka 120a6e
    m_miniToolBar->move(pos);
Shinya Kitaoka 120a6e
    m_miniToolBar->show();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::hideMiniToolBar() {
Shinya Kitaoka 120a6e
  // Hide the miniToolBar
Shinya Kitaoka 120a6e
  m_miniToolBar->hide();
Shinya Kitaoka 120a6e
  // Store the current Font in the application
Shinya Kitaoka 120a6e
  QTextCursor cursor = textCursor();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextBold() {
Shinya Kitaoka 120a6e
  QTextCharFormat fmt;
Shinya Kitaoka 120a6e
  fmt.setFontWeight(m_boldAction->isChecked() ? QFont::Bold : QFont::Normal);
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextItalic() {
Shinya Kitaoka 120a6e
  QTextCharFormat fmt;
Shinya Kitaoka 120a6e
  fmt.setFontItalic(m_italicAction->isChecked());
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextUnderline() {
Shinya Kitaoka 120a6e
  QTextCharFormat fmt;
Shinya Kitaoka 120a6e
  fmt.setFontUnderline(m_underlineAction->isChecked());
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextColor(const TPixel32 &color, bool isDragging) {
Shinya Kitaoka 120a6e
  if (isDragging) return;
Shinya Kitaoka 120a6e
  QColor col(color.r, color.g, color.b, color.m);
Shinya Kitaoka 120a6e
  QTextCharFormat fmt;
Shinya Kitaoka 120a6e
  fmt.setForeground(col);
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Shinya Kitaoka 120a6e
  colorChanged(col);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextFamily(const QString &f) {
Shinya Kitaoka 120a6e
  QTextCharFormat fmt;
Shinya Kitaoka 120a6e
  fmt.setFontFamily(f);
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextSize(const QString &p) {
Shinya Kitaoka 120a6e
  QTextCharFormat fmt;
Shinya Kitaoka 120a6e
  fmt.setFontPointSize(p.toFloat());
Shinya Kitaoka 120a6e
  mergeFormatOnWordOrSelection(fmt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::setTextAlign(QAction *a) {
Shinya Kitaoka 120a6e
  if (a == m_alignLeftAction)
Shinya Kitaoka 120a6e
    setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
  else if (a == m_alignCenterAction)
Shinya Kitaoka 120a6e
    setAlignment(Qt::AlignHCenter);
Shinya Kitaoka 120a6e
  else if (a == m_alignRightAction)
Shinya Kitaoka 120a6e
    setAlignment(Qt::AlignRight);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
Shinya Kitaoka 120a6e
  QTextCursor cursor = textCursor();
Shinya Kitaoka 120a6e
  if (!cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
Shinya Kitaoka 120a6e
  cursor.mergeCharFormat(format);
Shinya Kitaoka 120a6e
  mergeCurrentCharFormat(format);
Shinya Kitaoka 120a6e
  emit textChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::fontChanged(const QFont &f) {
Shinya Kitaoka 120a6e
  m_fontComboBox->setCurrentIndex(
Shinya Kitaoka 120a6e
      m_fontComboBox->findText(QFontInfo(f).family()));
Shinya Kitaoka 120a6e
  m_sizeComboBox->setCurrentIndex(
Shinya Kitaoka 120a6e
      m_sizeComboBox->findText(QString::number(f.pointSize())));
Shinya Kitaoka 120a6e
  m_boldAction->setChecked(f.bold());
Shinya Kitaoka 120a6e
  m_italicAction->setChecked(f.italic());
Shinya Kitaoka 120a6e
  m_underlineAction->setChecked(f.underline());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::colorChanged(const QColor &c) {
Shinya Kitaoka 120a6e
  m_colorField->setColor(TPixel32(c.red(), c.green(), c.blue(), c.alpha()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::alignmentChanged(Qt::Alignment a) {
Shinya Kitaoka 120a6e
  if (a & Qt::AlignLeft) {
Shinya Kitaoka 120a6e
    m_alignLeftAction->setChecked(true);
Shinya Kitaoka 120a6e
  } else if (a & Qt::AlignHCenter) {
Shinya Kitaoka 120a6e
    m_alignCenterAction->setChecked(true);
Shinya Kitaoka 120a6e
  } else if (a & Qt::AlignRight) {
Shinya Kitaoka 120a6e
    m_alignRightAction->setChecked(true);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::onCurrentCharFormatChanged(const QTextCharFormat &format) {
Shinya Kitaoka 120a6e
  fontChanged(format.font());
Shinya Kitaoka 120a6e
  colorChanged(format.foreground().color());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::onCursorPositionChanged() { alignmentChanged(alignment()); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::onShowMiniToolBarClicked() {
Shinya Kitaoka 120a6e
  showMiniToolBar(m_button->pos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DvTextEdit::onSelectionChanged() {
Shinya Kitaoka 120a6e
  QTextCursor cursor = textCursor();
Shinya Kitaoka 120a6e
  if (!cursor.hasSelection()) m_button->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------