Skip to content

Commit

Permalink
Allow alignment of text.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Dec 20, 2016
1 parent f8fd514 commit 3f37fd0
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 10 deletions.
127 changes: 117 additions & 10 deletions OMEdit/OMEditGUI/Modeling/DocumentationWidget.cpp
Expand Up @@ -50,6 +50,7 @@
#include <QDesktopWidget>
#include <QWebFrame>
#include <QWidgetAction>
#include <QButtonGroup>

/*!
* \class DocumentationWidget
Expand Down Expand Up @@ -148,42 +149,37 @@ DocumentationWidget::DocumentationWidget(QWidget *pParent)
mpBoldAction->setShortcut(QKeySequence("Ctrl+b"));
mpBoldAction->setCheckable(true);
connect(mpBoldAction, SIGNAL(triggered()), mpHTMLEditor->pageAction(QWebPage::ToggleBold), SLOT(trigger()));
connect(mpHTMLEditor->pageAction(QWebPage::ToggleBold), SIGNAL(changed()), SLOT(updateActions()));
// italic action
mpItalicAction = new QAction(QIcon(":/Resources/icons/italic-icon.svg"), Helper::italic, this);
mpItalicAction->setStatusTip(tr("Italicize your text"));
mpItalicAction->setShortcut(QKeySequence("Ctrl+i"));
mpItalicAction->setCheckable(true);
connect(mpItalicAction, SIGNAL(triggered()), mpHTMLEditor->pageAction(QWebPage::ToggleItalic), SLOT(trigger()));
connect(mpHTMLEditor->pageAction(QWebPage::ToggleItalic), SIGNAL(changed()), SLOT(updateActions()));
// underline action
mpUnderlineAction = new QAction(QIcon(":/Resources/icons/underline-icon.svg"), Helper::underline, this);
mpUnderlineAction->setStatusTip(tr("Underline your text"));
mpUnderlineAction->setShortcut(QKeySequence("Ctrl+u"));
mpUnderlineAction->setCheckable(true);
connect(mpUnderlineAction, SIGNAL(triggered()), mpHTMLEditor->pageAction(QWebPage::ToggleUnderline), SLOT(trigger()));
connect(mpHTMLEditor->pageAction(QWebPage::ToggleUnderline), SIGNAL(changed()), SLOT(updateActions()));
// strikethrough action
mpStrikethroughAction = new QAction(QIcon(":/Resources/icons/strikethrough-icon.svg"), tr("Strikethrough"), this);
mpStrikethroughAction->setStatusTip(tr("Cross something out by drawing a line through it"));
mpStrikethroughAction->setCheckable(true);
connect(mpStrikethroughAction, SIGNAL(triggered()), mpHTMLEditor->pageAction(QWebPage::ToggleStrikethrough), SLOT(trigger()));
connect(mpHTMLEditor->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(changed()), SLOT(updateActions()));
// subscript superscript action group
QActionGroup *pSubscriptSuperscriptActionGroup = new QActionGroup(this);
pSubscriptSuperscriptActionGroup->setExclusive(true);
// subscript action
mpSubscriptAction = new QAction(QIcon(":/Resources/icons/subscript-icon.svg"), tr("Subscript"), pSubscriptSuperscriptActionGroup);
mpSubscriptAction->setStatusTip(tr("Type very small letters just below the line of text"));
mpSubscriptAction->setCheckable(true);
connect(mpSubscriptAction, SIGNAL(triggered()), mpHTMLEditor->pageAction(QWebPage::ToggleSubscript), SLOT(trigger()));
connect(mpHTMLEditor->pageAction(QWebPage::ToggleSubscript), SIGNAL(changed()), SLOT(updateActions()));
// superscript action
mpSuperscriptAction = new QAction(QIcon(":/Resources/icons/superscript-icon.svg"), tr("Superscript"), pSubscriptSuperscriptActionGroup);
mpSuperscriptAction->setStatusTip(tr("Type very small letters just above the line of text"));
mpSuperscriptAction->setCheckable(true);
connect(mpSuperscriptAction, SIGNAL(triggered()), mpHTMLEditor->pageAction(QWebPage::ToggleSuperscript), SLOT(trigger()));
connect(mpHTMLEditor->pageAction(QWebPage::ToggleSuperscript), SIGNAL(changed()), SLOT(updateActions()));
// text color action
// text color toobutton
mTextColor = Qt::black;
mpTextColorDialog = new QColorDialog;
mpTextColorDialog->setWindowFlags(Qt::Widget);
Expand All @@ -198,12 +194,13 @@ DocumentationWidget::DocumentationWidget(QWidget *pParent)
connect(mpTextColorDialog, SIGNAL(rejected()), pTextColorMenu, SLOT(hide()));
mpTextColorToolButton = new QToolButton;
mpTextColorToolButton->setText(tr("Text Color"));
mpTextColorToolButton->setToolTip(mpTextColorToolButton->text());
mpTextColorToolButton->setStatusTip(tr("Change the color of your text"));
mpTextColorToolButton->setMenu(pTextColorMenu);
mpTextColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
mpTextColorToolButton->setIcon(createPixmapForToolButton(mTextColor, QIcon(":/Resources/icons/text-color-icon.svg")));
connect(mpTextColorToolButton, SIGNAL(clicked()), SLOT(applyTextColor()));
// background color action
// background color toolbutton
mBackgroundColor = Qt::white;
mpBackgroundColorDialog = new QColorDialog;
mpBackgroundColorDialog->setWindowFlags(Qt::Widget);
Expand All @@ -218,11 +215,52 @@ DocumentationWidget::DocumentationWidget(QWidget *pParent)
connect(mpBackgroundColorDialog, SIGNAL(rejected()), pBackgroundColorMenu, SLOT(hide()));
mpBackgroundColorToolButton = new QToolButton;
mpBackgroundColorToolButton->setText(tr("Background Color"));
mpBackgroundColorToolButton->setToolTip(mpBackgroundColorToolButton->text());
mpBackgroundColorToolButton->setStatusTip(tr("Change the color of your text"));
mpBackgroundColorToolButton->setMenu(pBackgroundColorMenu);
mpBackgroundColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
mpBackgroundColorToolButton->setIcon(createPixmapForToolButton(mBackgroundColor, QIcon(":/Resources/icons/background-color-icon.svg")));
connect(mpBackgroundColorToolButton, SIGNAL(clicked()), SLOT(applyBackgroundColor()));
// align left toolbutton
mpAlignLeftToolButton = new QToolButton;
mpAlignLeftToolButton->setText(tr("Align Left"));
mpAlignLeftToolButton->setToolTip(mpAlignLeftToolButton->text());
mpAlignLeftToolButton->setStatusTip(tr("Aligns the text to the left"));
mpAlignLeftToolButton->setIcon(QIcon(":/Resources/icons/align-left.svg"));
mpAlignLeftToolButton->setCheckable(true);
mpAlignLeftToolButton->setChecked(true);
connect(mpAlignLeftToolButton, SIGNAL(clicked()), SLOT(alignLeft()));
// align center toolbutton
mpAlignCenterToolButton = new QToolButton;
mpAlignCenterToolButton->setText(tr("Align Center"));
mpAlignCenterToolButton->setToolTip(mpAlignCenterToolButton->text());
mpAlignCenterToolButton->setStatusTip(tr("Aligns the text to the center"));
mpAlignCenterToolButton->setIcon(QIcon(":/Resources/icons/align-center.svg"));
mpAlignCenterToolButton->setCheckable(true);
connect(mpAlignCenterToolButton, SIGNAL(clicked()), SLOT(alignCenter()));
// align right toolbutton
mpAlignRightToolButton = new QToolButton;
mpAlignRightToolButton->setText(tr("Align Right"));
mpAlignRightToolButton->setToolTip(mpAlignRightToolButton->text());
mpAlignRightToolButton->setStatusTip(tr("Aligns the text to the right"));
mpAlignRightToolButton->setIcon(QIcon(":/Resources/icons/align-right.svg"));
mpAlignRightToolButton->setCheckable(true);
connect(mpAlignRightToolButton, SIGNAL(clicked()), SLOT(alignRight()));
// justify toolbutton
mpJustifyToolButton = new QToolButton;
mpJustifyToolButton->setText(tr("Justify"));
mpJustifyToolButton->setToolTip(mpJustifyToolButton->text());
mpJustifyToolButton->setStatusTip(tr("Justifies the text evenly"));
mpJustifyToolButton->setIcon(QIcon(":/Resources/icons/justify.svg"));
mpJustifyToolButton->setCheckable(true);
connect(mpJustifyToolButton, SIGNAL(clicked()), SLOT(justify()));
// alignment button group
QButtonGroup *pAlignmentButtonGroup = new QButtonGroup;
pAlignmentButtonGroup->setExclusive(true);
pAlignmentButtonGroup->addButton(mpAlignLeftToolButton);
pAlignmentButtonGroup->addButton(mpAlignCenterToolButton);
pAlignmentButtonGroup->addButton(mpAlignRightToolButton);
pAlignmentButtonGroup->addButton(mpJustifyToolButton);
// add actions to toolbar
mpEditorToolBar->addAction(mpBoldAction);
mpEditorToolBar->addAction(mpItalicAction);
Expand All @@ -233,6 +271,13 @@ DocumentationWidget::DocumentationWidget(QWidget *pParent)
mpEditorToolBar->addSeparator();
mpEditorToolBar->addWidget(mpTextColorToolButton);
mpEditorToolBar->addWidget(mpBackgroundColorToolButton);
mpEditorToolBar->addSeparator();
mpEditorToolBar->addWidget(mpAlignLeftToolButton);
mpEditorToolBar->addWidget(mpAlignCenterToolButton);
mpEditorToolBar->addWidget(mpAlignRightToolButton);
mpEditorToolBar->addWidget(mpJustifyToolButton);
// update the actions whenever the selectionChanged signal is raised.
connect(mpHTMLEditor->page(), SIGNAL(selectionChanged()), SLOT(updateActions()));
// add a layout to html editor widget
QVBoxLayout *pHTMLWidgetLayout = new QVBoxLayout;
pHTMLWidgetLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Expand Down Expand Up @@ -692,7 +737,7 @@ void DocumentationWidget::toggleEditor(int tabIndex)

/*!
* \brief DocumentationWidget::updateActions
* Slot activated when QWebView::pageAction() changed SIGNAL is raised.\n
* Slot activated when QWebView::page() selecionChanged SIGNAL is raised.\n
* Updates the actions according to the cursor position.
*/
void DocumentationWidget::updateActions()
Expand All @@ -703,32 +748,94 @@ void DocumentationWidget::updateActions()
mpStrikethroughAction->setChecked(mpHTMLEditor->pageAction(QWebPage::ToggleStrikethrough)->isChecked());
mpSubscriptAction->setChecked(mpHTMLEditor->pageAction(QWebPage::ToggleSubscript)->isChecked());
mpSuperscriptAction->setChecked(mpHTMLEditor->pageAction(QWebPage::ToggleSuperscript)->isChecked());
mpAlignLeftToolButton->setChecked(queryCommandState("justifyLeft"));
mpAlignCenterToolButton->setChecked(queryCommandState("justifyCenter"));
mpAlignRightToolButton->setChecked(queryCommandState("justifyRight"));
mpJustifyToolButton->setChecked(queryCommandState("justifyFull"));
}

/*!
* \brief DocumentationWidget::applyTextColor
* SLOT activated when text color button is clicked.\n
* \sa DocumentationWidget::applyTextColor(QColor color)
*/
void DocumentationWidget::applyTextColor()
{
applyTextColor(mTextColor);
}

/*!
* \brief DocumentationWidget::applyTextColor
* SLOT activated when user selects a text color.\n
* Applies the text color by executing command foreColor.
* \param color
*/
void DocumentationWidget::applyTextColor(QColor color)
{
mTextColor = color;
mpTextColorToolButton->setIcon(createPixmapForToolButton(mTextColor, QIcon(":/Resources/icons/text-color-icon.svg")));
execCommand("foreColor", color.name());
}

/*!
* \brief DocumentationWidget::applyBackgroundColor
* SLOT activated when background color button is clicked.\n
* \sa DocumentationWidget::applyBackgroundColor(QColor color)
*/
void DocumentationWidget::applyBackgroundColor()
{
applyTextColor(mBackgroundColor);
applyBackgroundColor(mBackgroundColor);
}

/*!
* \brief DocumentationWidget::applyBackgroundColor
* SLOT activated when user selects a baclground color.\n
* Applies the text color by executing command hiliteColor.
* \param color
*/
void DocumentationWidget::applyBackgroundColor(QColor color)
{
mBackgroundColor = color;
mpBackgroundColorToolButton->setIcon(createPixmapForToolButton(mBackgroundColor, QIcon(":/Resources/icons/background-color-icon.svg")));
execCommand("hiliteColor", color.name());
}

/*!
* \brief DocumentationWidget::alignLeft
* Aligns the text left by executing command justifyLeft.
*/
void DocumentationWidget::alignLeft()
{
execCommand("justifyLeft");
}

/*!
* \brief DocumentationWidget::alignCenter
* Aligns the text center by executing command justifyCenter.
*/
void DocumentationWidget::alignCenter()
{
execCommand("justifyCenter");
}

/*!
* \brief DocumentationWidget::alignRight
* Aligns the text right by executing command justifyRight.
*/
void DocumentationWidget::alignRight()
{
execCommand("justifyRight");
}

/*!
* \brief DocumentationWidget::justify
* Justifies the text by executing command justifyFull.
*/
void DocumentationWidget::justify()
{
execCommand("justifyFull");
}

/*!
* \brief DocumentationWidget::updateHTMLSourceEditor
* Slot activated when QWebView::page() contentsChanged SIGNAL is rasied.\n
Expand Down
8 changes: 8 additions & 0 deletions OMEdit/OMEditGUI/Modeling/DocumentationWidget.h
Expand Up @@ -100,6 +100,10 @@ class DocumentationWidget : public QWidget
QColor mBackgroundColor;
QColorDialog *mpBackgroundColorDialog;
QToolButton *mpBackgroundColorToolButton;
QToolButton *mpAlignLeftToolButton;
QToolButton *mpAlignCenterToolButton;
QToolButton *mpAlignRightToolButton;
QToolButton *mpJustifyToolButton;
HTMLEditor *mpHTMLSourceEditor;
EditType mEditType;
QList<DocumentationHistory> *mpDocumentationHistoryList;
Expand All @@ -125,6 +129,10 @@ public slots:
void applyTextColor(QColor color);
void applyBackgroundColor();
void applyBackgroundColor(QColor color);
void alignLeft();
void alignCenter();
void alignRight();
void justify();
void updateHTMLSourceEditor();
void updateDocumentationHistory();
};
Expand Down
114 changes: 114 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/align-center.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3f37fd0

Please sign in to comment.