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