-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolormodifier.cpp
More file actions
67 lines (46 loc) · 1.49 KB
/
colormodifier.cpp
File metadata and controls
67 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "colormodifier.h"
// Qt includes
#include <QDebug>
#include <QTextBlock>
#include <QTextCursor>
// QtCreator includes
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/texteditor.h>
using namespace Core;
using namespace TextEditor;
namespace ColorPicker {
namespace Internal {
////////////////////////// ColorModifierImpl //////////////////////////
class ColorModifierImpl
{
public:
ColorModifierImpl();
/* functions */
};
ColorModifierImpl::ColorModifierImpl()
{}
////////////////////////// ColorModifier //////////////////////////
ColorModifier::ColorModifier(QObject *parent) :
QObject(parent),
d(new ColorModifierImpl)
{
}
ColorModifier::~ColorModifier()
{}
void ColorModifier::insertColor(const QColor &newValue, ColorFormat asFormat)
{
IEditor *currentEditor = EditorManager::instance()->currentEditor();
if (!currentEditor)
return;
TextEditorWidget *editorWidget = qobject_cast<TextEditorWidget *>(currentEditor->widget());
QTextCursor currentCursor = editorWidget->textCursor();
QString newText = colorToString(newValue, asFormat);
currentCursor.insertText(newText);
currentCursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor,
newText.size());
currentCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
newText.size());
editorWidget->setTextCursor(currentCursor);
}
} // namespace Internal
} // namespace ColorPicker