* work done for color scheme
This commit is contained in:
parent
39bdd66dbb
commit
6fd4371b43
|
@ -2,6 +2,8 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "qsynedit/highlighter/cpp.h"
|
#include "qsynedit/highlighter/cpp.h"
|
||||||
|
#include "qsynedit/Constants.h"
|
||||||
|
#include "colorscheme.h"
|
||||||
|
|
||||||
HighlighterManager highlighterManager;
|
HighlighterManager highlighterManager;
|
||||||
|
|
||||||
|
@ -26,6 +28,14 @@ PSynHighlighter HighlighterManager::getHighlighter(const QString &filename)
|
||||||
return PSynHighlighter();
|
return PSynHighlighter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PSynHighlighter HighlighterManager::copyHighlighter(PSynHighlighter highlighter)
|
||||||
|
{
|
||||||
|
if (!highlighter)
|
||||||
|
return PSynHighlighter();
|
||||||
|
if (highlighter->getName() == SYN_HIGHLIGHTER_CPP)
|
||||||
|
return getCppHighlighter();
|
||||||
|
}
|
||||||
|
|
||||||
PSynHighlighter HighlighterManager::getCppHighlighter()
|
PSynHighlighter HighlighterManager::getCppHighlighter()
|
||||||
{
|
{
|
||||||
SynEditCppHighlighter* highlighter = new SynEditCppHighlighter();
|
SynEditCppHighlighter* highlighter = new SynEditCppHighlighter();
|
||||||
|
@ -53,3 +63,32 @@ PSynHighlighter HighlighterManager::getCppHighlighter()
|
||||||
highlighter->variableAttribute()->setForeground(0x400080);
|
highlighter->variableAttribute()->setForeground(0x400080);
|
||||||
return pHighlighter;
|
return pHighlighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QString &schemeName)
|
||||||
|
{
|
||||||
|
if (!highlighter)
|
||||||
|
return;
|
||||||
|
if (highlighter->getName() == SYN_HIGHLIGHTER_CPP) {
|
||||||
|
for (QString name: highlighter->attributes().keys()) {
|
||||||
|
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
|
||||||
|
if (item) {
|
||||||
|
PSynHighlighterAttribute attr = highlighter->attributes()[name];
|
||||||
|
attr->setBackground(item->background());
|
||||||
|
attr->setForeground(item->foreground());
|
||||||
|
SynFontStyles styles = SynFontStyle::fsNone;
|
||||||
|
if (item->bold()) {
|
||||||
|
styles.setFlag(SynFontStyle::fsBold);
|
||||||
|
}
|
||||||
|
if (item->italic()) {
|
||||||
|
styles.setFlag(SynFontStyle::fsItalic);
|
||||||
|
}
|
||||||
|
if (item->underlined()) {
|
||||||
|
styles.setFlag(SynFontStyle::fsUnderline);
|
||||||
|
}
|
||||||
|
if (item->strikeout()) {
|
||||||
|
styles.setFlag(SynFontStyle::fsStrikeOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@ public:
|
||||||
HighlighterManager();
|
HighlighterManager();
|
||||||
|
|
||||||
PSynHighlighter getHighlighter(const QString& filename);
|
PSynHighlighter getHighlighter(const QString& filename);
|
||||||
|
PSynHighlighter copyHighlighter(PSynHighlighter highlighter);
|
||||||
PSynHighlighter getCppHighlighter();
|
PSynHighlighter getCppHighlighter();
|
||||||
|
void applyColorScheme(PSynHighlighter highlighter, const QString& schemeName);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern HighlighterManager highlighterManager;
|
extern HighlighterManager highlighterManager;
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -302,6 +302,48 @@ QString ColorManager::copy(const QString &sourceName)
|
||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ColorManager::restoreToDefault(const QString &name)
|
||||||
|
{
|
||||||
|
PColorScheme scheme = get(name);
|
||||||
|
if (!scheme)
|
||||||
|
return false;
|
||||||
|
if (!scheme->customed())
|
||||||
|
return false;
|
||||||
|
QString fullPath = generateFullPathname(name,scheme->bundled(),false);
|
||||||
|
PColorScheme oldScheme = ColorScheme::load(fullPath);
|
||||||
|
if (!oldScheme)
|
||||||
|
throw FileError(QObject::tr("Can't Find the color scheme file %1!").arg(fullPath));
|
||||||
|
fullPath = generateFullPathname(name,scheme->bundled(),true);
|
||||||
|
QFile file(fullPath);
|
||||||
|
if (file.exists() && !file.remove())
|
||||||
|
throw FileError(QObject::tr("Can't remove the color scheme file %1!").arg(fullPath));
|
||||||
|
oldScheme->setBundled(scheme->bundled());
|
||||||
|
oldScheme->setCustomed(false);
|
||||||
|
mSchemes[name]=oldScheme;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ColorManager::remove(const QString &name)
|
||||||
|
{
|
||||||
|
PColorScheme scheme = get(name);
|
||||||
|
if (!scheme)
|
||||||
|
return false;
|
||||||
|
if (scheme->bundled())
|
||||||
|
return false;
|
||||||
|
if (scheme->customed()) {
|
||||||
|
QString fullPath = generateFullPathname(name,false,true);
|
||||||
|
QFile file(fullPath);
|
||||||
|
if (!file.remove())
|
||||||
|
throw FileError(QObject::tr("Can't remove the color scheme file %1!").arg(fullPath));
|
||||||
|
}
|
||||||
|
QString fullPath = generateFullPathname(name,false,false);
|
||||||
|
QFile file(fullPath);
|
||||||
|
if (!file.remove())
|
||||||
|
throw FileError(QObject::tr("Can't remove the color scheme file %1!").arg(fullPath));
|
||||||
|
mSchemes.remove(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString ColorManager::generateFilename(const QString &name, bool isCustomed)
|
QString ColorManager::generateFilename(const QString &name, bool isCustomed)
|
||||||
{
|
{
|
||||||
QString newName = name;
|
QString newName = name;
|
||||||
|
@ -328,11 +370,13 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isBundled, bool
|
||||||
QFileInfo fileInfo = list[i];
|
QFileInfo fileInfo = list[i];
|
||||||
QString name = fileInfo.fileName();
|
QString name = fileInfo.fileName();
|
||||||
if (name.toLower().endsWith(suffix)) {
|
if (name.toLower().endsWith(suffix)) {
|
||||||
if (!isCustomed && name.toLower().endsWith(customSuffix))
|
// if (!isCustomed && name.toLower().endsWith(customSuffix))
|
||||||
continue;
|
// continue;
|
||||||
PColorScheme scheme = ColorScheme::load(fileInfo.absoluteFilePath());
|
|
||||||
name.remove(name.length()-suffix.length(),suffix.length());
|
name.remove(name.length()-suffix.length(),suffix.length());
|
||||||
name.replace('_',' ');
|
name.replace('_',' ');
|
||||||
|
if (!isValidName(name))
|
||||||
|
continue;
|
||||||
|
PColorScheme scheme = ColorScheme::load(fileInfo.absoluteFilePath());
|
||||||
if (!isCustomed) {
|
if (!isCustomed) {
|
||||||
scheme->setBundled(isBundled);
|
scheme->setBundled(isBundled);
|
||||||
scheme->setCustomed(false);
|
scheme->setCustomed(false);
|
||||||
|
@ -504,16 +548,33 @@ bool ColorManager::rename(const QString &oldName, const QString &newName)
|
||||||
PColorScheme scheme = get(oldName);
|
PColorScheme scheme = get(oldName);
|
||||||
if (!scheme)
|
if (!scheme)
|
||||||
return false;
|
return false;
|
||||||
|
if (scheme->bundled())
|
||||||
|
return false;
|
||||||
|
if (scheme->customed()) {
|
||||||
|
QString oldfullPath = generateFullPathname(oldName,false,true);
|
||||||
|
QString fullpath = generateFullPathname(newName,false,true);
|
||||||
|
QFile oldFile(oldfullPath);
|
||||||
|
if (oldFile.exists() && !oldFile.rename(fullpath))
|
||||||
|
throw FileError(QObject::tr("Rename file '%1' to '%2' failed!").arg(oldfullPath).arg(fullpath));
|
||||||
|
}
|
||||||
|
QString oldfullPath = generateFullPathname(oldName,false,false);
|
||||||
|
QString fullpath = generateFullPathname(newName,false,false);
|
||||||
|
QFile oldFile(oldfullPath);
|
||||||
|
if (oldFile.exists() && !oldFile.rename(fullpath))
|
||||||
|
throw FileError(QObject::tr("Rename file '%1' to '%2' failed!").arg(oldfullPath).arg(fullpath));
|
||||||
|
mSchemes.remove(oldName);
|
||||||
mSchemes[newName] = scheme;
|
mSchemes[newName] = scheme;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PColorScheme ColorManager::remove(const QString &name)
|
bool ColorManager::add(const QString &name, PColorScheme scheme)
|
||||||
{
|
{
|
||||||
PColorScheme scheme=get(name);
|
if (mSchemes.contains(name))
|
||||||
if (scheme)
|
throw FileError(QObject::tr("Scheme '%1' already exists!").arg(name));
|
||||||
mSchemes.remove(name);
|
scheme->setBundled(false);
|
||||||
return scheme;
|
scheme->setCustomed(false);
|
||||||
|
mSchemes[name] = scheme;
|
||||||
|
saveScheme(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
PColorScheme ColorManager::get(const QString &name)
|
PColorScheme ColorManager::get(const QString &name)
|
||||||
|
|
|
@ -130,8 +130,10 @@ public:
|
||||||
|
|
||||||
bool exists(const QString name);
|
bool exists(const QString name);
|
||||||
QString copy(const QString& source);
|
QString copy(const QString& source);
|
||||||
|
bool restoreToDefault(const QString& name);
|
||||||
|
bool remove(const QString& name);
|
||||||
bool rename(const QString& oldName, const QString& newName);
|
bool rename(const QString& oldName, const QString& newName);
|
||||||
PColorScheme remove(const QString& name);
|
bool add(const QString& name, PColorScheme scheme);
|
||||||
PColorScheme get(const QString& name);
|
PColorScheme get(const QString& name);
|
||||||
PColorSchemeItem getItem(const QString& schemeName, const QString& itemName);
|
PColorSchemeItem getItem(const QString& schemeName, const QString& itemName);
|
||||||
bool isValidName(const QString& name);
|
bool isValidName(const QString& name);
|
||||||
|
|
|
@ -59,12 +59,11 @@ bool FileCompiler::prepareForCompile()
|
||||||
mCompiler = compilerSet()->cppCompiler();
|
mCompiler = compilerSet()->cppCompiler();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(tr("Can't the compiler for file %1").arg(mFileName));
|
error(tr("Can't find the compiler for file %1").arg(mFileName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mArguments += getLibraryArguments();
|
mArguments += getLibraryArguments();
|
||||||
|
|
||||||
|
|
||||||
log(tr("Processing %1 source file:").arg(strFileType));
|
log(tr("Processing %1 source file:").arg(strFileType));
|
||||||
log("------------------");
|
log("------------------");
|
||||||
log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler));
|
log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler));
|
||||||
|
|
|
@ -127,7 +127,7 @@ bool Editor::save(bool force, bool reparse) {
|
||||||
//is this file writable;
|
//is this file writable;
|
||||||
if (!force && !info.isWritable()) {
|
if (!force && !info.isWritable()) {
|
||||||
QMessageBox::information(pMainWindow,tr("Fail"),
|
QMessageBox::information(pMainWindow,tr("Fail"),
|
||||||
QString(QObject::tr("File %s is not writable!")));
|
tr("File %1 is not writable!").arg(mFilename));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this->modified()|| force) {
|
if (this->modified()|| force) {
|
||||||
|
@ -295,22 +295,22 @@ void Editor::copyAsHTML()
|
||||||
|
|
||||||
SynExporterHTML.setTitle(QFileInfo(mFilename).fileName());
|
SynExporterHTML.setTitle(QFileInfo(mFilename).fileName());
|
||||||
SynExporterHTML.setExportAsText(false);
|
SynExporterHTML.setExportAsText(false);
|
||||||
SynExporterHTML.setUseBackground(true);
|
SynExporterHTML.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
||||||
SynExporterHTML.setFont(font());
|
SynExporterHTML.setFont(font());
|
||||||
SynExporterHTML.setHighlighter(highlighter());
|
PSynHighlighter hl = highlighter();
|
||||||
|
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
||||||
|
hl = highlighterManager.copyHighlighter(highlighter());
|
||||||
|
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
||||||
|
}
|
||||||
|
SynExporterHTML.setHighlighter(hl);
|
||||||
SynExporterHTML.setCreateHTMLFragment(true);
|
SynExporterHTML.setCreateHTMLFragment(true);
|
||||||
//SynExporterRTF.OnFormatToken := ExporterFormatToken;
|
|
||||||
|
|
||||||
|
|
||||||
SynExporterHTML.ExportRange(lines(),blockBegin(),blockEnd());
|
SynExporterHTML.ExportRange(lines(),blockBegin(),blockEnd());
|
||||||
|
|
||||||
//SynExporterHTML.CopyToClipboard();
|
|
||||||
|
|
||||||
QMimeData * mimeData = new QMimeData;
|
QMimeData * mimeData = new QMimeData;
|
||||||
|
|
||||||
//sethtml will convert buffer to QString , which will cause encoding trouble
|
//sethtml will convert buffer to QString , which will cause encoding trouble
|
||||||
mimeData->setData(SynExporterHTML.clipboardFormat(),SynExporterHTML.buffer());
|
mimeData->setData(SynExporterHTML.clipboardFormat(),SynExporterHTML.buffer());
|
||||||
//mimeData->setHtml("<span><style> b {color:red;} </style><b>test</b></span>");
|
|
||||||
mimeData->setText(selText());
|
mimeData->setText(selText());
|
||||||
|
|
||||||
QGuiApplication::clipboard()->clear();
|
QGuiApplication::clipboard()->clear();
|
||||||
|
@ -464,31 +464,7 @@ void Editor::applySettings()
|
||||||
|
|
||||||
void Editor::applyColorScheme(const QString& schemeName)
|
void Editor::applyColorScheme(const QString& schemeName)
|
||||||
{
|
{
|
||||||
if (highlighter()) {
|
highlighterManager.applyColorScheme(highlighter(),schemeName);
|
||||||
if (highlighter()->getName() == SYN_HIGHLIGHTER_CPP) {
|
|
||||||
for (QString name: highlighter()->attributes().keys()) {
|
|
||||||
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
|
|
||||||
if (item) {
|
|
||||||
PSynHighlighterAttribute attr = highlighter()->attributes()[name];
|
|
||||||
attr->setBackground(item->background());
|
|
||||||
attr->setForeground(item->foreground());
|
|
||||||
SynFontStyles styles = SynFontStyle::fsNone;
|
|
||||||
if (item->bold()) {
|
|
||||||
styles.setFlag(SynFontStyle::fsBold);
|
|
||||||
}
|
|
||||||
if (item->italic()) {
|
|
||||||
styles.setFlag(SynFontStyle::fsItalic);
|
|
||||||
}
|
|
||||||
if (item->underlined()) {
|
|
||||||
styles.setFlag(SynFontStyle::fsUnderline);
|
|
||||||
}
|
|
||||||
if (item->strikeout()) {
|
|
||||||
styles.setFlag(SynFontStyle::fsStrikeOut);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PColorSchemeItem item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_LINE);
|
PColorSchemeItem item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_LINE);
|
||||||
if (item) {
|
if (item) {
|
||||||
setActiveLineColor(item->background());
|
setActiveLineColor(item->background());
|
||||||
|
|
|
@ -170,6 +170,7 @@ void MainWindow::applySettings()
|
||||||
font.setStyleStrategy(QFont::PreferAntialias);
|
font.setStyleStrategy(QFont::PreferAntialias);
|
||||||
QApplication * app = dynamic_cast<QApplication*>(QApplication::instance());
|
QApplication * app = dynamic_cast<QApplication*>(QApplication::instance());
|
||||||
app->setFont(font);
|
app->setFont(font);
|
||||||
|
this->setFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateStatusbarForLineCol()
|
void MainWindow::updateStatusbarForLineCol()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ui_editorclipboardwidget.h"
|
#include "ui_editorclipboardwidget.h"
|
||||||
#include "../settings.h"
|
#include "../settings.h"
|
||||||
#include "../mainwindow.h"
|
#include "../mainwindow.h"
|
||||||
|
#include "../colorscheme.h"
|
||||||
|
|
||||||
EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent) :
|
EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent) :
|
||||||
SettingsWidget(name,group,parent),
|
SettingsWidget(name,group,parent),
|
||||||
|
@ -10,6 +11,19 @@ EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString&
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->cbCopyWithFormatAs->addItem("None");
|
ui->cbCopyWithFormatAs->addItem("None");
|
||||||
ui->cbCopyWithFormatAs->addItem("HTML");
|
ui->cbCopyWithFormatAs->addItem("HTML");
|
||||||
|
|
||||||
|
for (QString name: pColorManager->getSchemes()) {
|
||||||
|
ui->cbHTMLColorScheme->addItem(name);
|
||||||
|
ui->cbRTFColorScheme->addItem(name);
|
||||||
|
}
|
||||||
|
connect(ui->chkCopyRTFUseEditorColor,
|
||||||
|
&QCheckBox::stateChanged,
|
||||||
|
this,
|
||||||
|
&EditorClipboardWidget::onUseSchemeChanged);
|
||||||
|
connect(ui->chkCopyHTMLUseEditorColor,
|
||||||
|
&QCheckBox::stateChanged,
|
||||||
|
this,
|
||||||
|
&EditorClipboardWidget::onUseSchemeChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorClipboardWidget::~EditorClipboardWidget()
|
EditorClipboardWidget::~EditorClipboardWidget()
|
||||||
|
@ -17,6 +31,12 @@ EditorClipboardWidget::~EditorClipboardWidget()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorClipboardWidget::onUseSchemeChanged()
|
||||||
|
{
|
||||||
|
ui->cbRTFColorScheme->setEnabled(!ui->chkCopyRTFUseEditorColor->isChecked());
|
||||||
|
ui->cbHTMLColorScheme->setEnabled(!ui->chkCopyHTMLUseEditorColor->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
void EditorClipboardWidget::doLoad()
|
void EditorClipboardWidget::doLoad()
|
||||||
{
|
{
|
||||||
//pSettings->editor().load();
|
//pSettings->editor().load();
|
||||||
|
@ -30,13 +50,11 @@ void EditorClipboardWidget::doLoad()
|
||||||
pSettings->editor().copyWithFormatAs())) );
|
pSettings->editor().copyWithFormatAs())) );
|
||||||
ui->chkCopyRTFUseBackground->setChecked(pSettings->editor().copyRTFUseBackground());
|
ui->chkCopyRTFUseBackground->setChecked(pSettings->editor().copyRTFUseBackground());
|
||||||
ui->chkCopyRTFUseEditorColor->setChecked(pSettings->editor().copyRTFUseEditorColor());
|
ui->chkCopyRTFUseEditorColor->setChecked(pSettings->editor().copyRTFUseEditorColor());
|
||||||
//todo
|
ui->cbRTFColorScheme->setCurrentText(pSettings->editor().colorScheme());
|
||||||
//ui->cbCopyRTFColorScheme
|
|
||||||
ui->chkCopyHTMLUseBackground->setChecked(pSettings->editor().copyHTMLUseBackground());
|
ui->chkCopyHTMLUseBackground->setChecked(pSettings->editor().copyHTMLUseBackground());
|
||||||
ui->chkCopyHTMLUseEditorColor->setChecked(pSettings->editor().copyHTMLUseEditorColor());
|
ui->chkCopyHTMLUseEditorColor->setChecked(pSettings->editor().copyHTMLUseEditorColor());
|
||||||
//todo
|
ui->cbHTMLColorScheme->setCurrentText(pSettings->editor().colorScheme());
|
||||||
//ui->cbCopyHTMLColorScheme
|
onUseSchemeChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorClipboardWidget::doSave()
|
void EditorClipboardWidget::doSave()
|
||||||
|
@ -49,10 +67,11 @@ void EditorClipboardWidget::doSave()
|
||||||
|
|
||||||
pSettings->editor().setCopyRTFUseBackground(ui->chkCopyRTFUseBackground->isChecked());
|
pSettings->editor().setCopyRTFUseBackground(ui->chkCopyRTFUseBackground->isChecked());
|
||||||
pSettings->editor().setCopyRTFUseEditorColor(ui->chkCopyRTFUseEditorColor->isChecked());
|
pSettings->editor().setCopyRTFUseEditorColor(ui->chkCopyRTFUseEditorColor->isChecked());
|
||||||
//todo
|
pSettings->editor().setCopyRTFColorScheme(ui->cbRTFColorScheme->currentText());
|
||||||
//ui->cbCopyRTFColorSchema
|
|
||||||
pSettings->editor().setCopyHTMLUseBackground(ui->chkCopyHTMLUseBackground->isChecked());
|
pSettings->editor().setCopyHTMLUseBackground(ui->chkCopyHTMLUseBackground->isChecked());
|
||||||
pSettings->editor().setCopyHTMLUseEditorColor(ui->chkCopyHTMLUseEditorColor->isChecked());
|
pSettings->editor().setCopyHTMLUseEditorColor(ui->chkCopyHTMLUseEditorColor->isChecked());
|
||||||
|
pSettings->editor().setCopyHTMLColorScheme(ui->cbHTMLColorScheme->currentText());
|
||||||
|
|
||||||
pSettings->editor().save();
|
pSettings->editor().save();
|
||||||
pMainWindow->updateEditorSettings();
|
pMainWindow->updateEditorSettings();
|
||||||
|
|
|
@ -16,6 +16,9 @@ public:
|
||||||
explicit EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
|
explicit EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
|
||||||
~EditorClipboardWidget();
|
~EditorClipboardWidget();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onUseSchemeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::EditorClipboardWidget *ui;
|
Ui::EditorClipboardWidget *ui;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) :
|
EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) :
|
||||||
SettingsWidget(name,group,parent),
|
SettingsWidget(name,group,parent),
|
||||||
|
@ -150,7 +152,7 @@ void EditorColorSchemeWidget::setCurrentSchemeModified()
|
||||||
ui->cbScheme->setItemData(ui->cbScheme->currentIndex(),
|
ui->cbScheme->setItemData(ui->cbScheme->currentIndex(),
|
||||||
mModifiedSchemeComboFont,Qt::FontRole);
|
mModifiedSchemeComboFont,Qt::FontRole);
|
||||||
ui->cbScheme->setFont(mModifiedSchemeComboFont);
|
ui->cbScheme->setFont(mModifiedSchemeComboFont);
|
||||||
ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
//ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
||||||
//we must reset the editor here, because this slot is processed after the onSettingChanged
|
//we must reset the editor here, because this slot is processed after the onSettingChanged
|
||||||
onSettingChanged();
|
onSettingChanged();
|
||||||
}
|
}
|
||||||
|
@ -227,9 +229,11 @@ void EditorColorSchemeWidget::onForegroundChanged()
|
||||||
PColorSchemeItem item = getCurrentItem();
|
PColorSchemeItem item = getCurrentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
ui->colorForeground->setVisible(ui->cbForeground->isChecked());
|
||||||
if (ui->cbForeground->isChecked()) {
|
if (ui->cbForeground->isChecked()) {
|
||||||
item->setForeground(ui->colorForeground->color());
|
item->setForeground(ui->colorForeground->color());
|
||||||
} else {
|
} else {
|
||||||
|
ui->colorForeground->setColor(QColor());
|
||||||
item->setForeground(QColor());
|
item->setForeground(QColor());
|
||||||
}
|
}
|
||||||
setCurrentSchemeModified();
|
setCurrentSchemeModified();
|
||||||
|
@ -240,9 +244,11 @@ void EditorColorSchemeWidget::onBackgroundChanged()
|
||||||
PColorSchemeItem item = getCurrentItem();
|
PColorSchemeItem item = getCurrentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
ui->colorBackground->setVisible(ui->cbBackground->isChecked());
|
||||||
if (ui->cbBackground->isChecked()) {
|
if (ui->cbBackground->isChecked()) {
|
||||||
item->setBackground(ui->colorBackground->color());
|
item->setBackground(ui->colorBackground->color());
|
||||||
} else {
|
} else {
|
||||||
|
ui->colorBackground->setColor(QColor());
|
||||||
item->setBackground(QColor());
|
item->setBackground(QColor());
|
||||||
}
|
}
|
||||||
setCurrentSchemeModified();
|
setCurrentSchemeModified();
|
||||||
|
@ -269,7 +275,7 @@ void EditorColorSchemeWidget::changeSchemeComboFont()
|
||||||
} else {
|
} else {
|
||||||
ui->cbScheme->setFont(mDefaultSchemeComboFont);
|
ui->cbScheme->setFont(mDefaultSchemeComboFont);
|
||||||
}
|
}
|
||||||
ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
//ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorColorSchemeWidget::doLoad()
|
void EditorColorSchemeWidget::doLoad()
|
||||||
|
@ -313,7 +319,9 @@ void EditorColorSchemeWidget::on_btnSchemeMenu_pressed()
|
||||||
menu.addAction(ui->actionRename_Scheme);
|
menu.addAction(ui->actionRename_Scheme);
|
||||||
menu.addAction(ui->actionDelete_Scheme);
|
menu.addAction(ui->actionDelete_Scheme);
|
||||||
}
|
}
|
||||||
menu.addAction(ui->actionCopy_Scheme);
|
QString name = ui->cbScheme->currentText();
|
||||||
|
if (!pColorManager->exists(name+ " Copy"))
|
||||||
|
menu.addAction(ui->actionCopy_Scheme);
|
||||||
menu.addAction(ui->actionExport_Scheme);
|
menu.addAction(ui->actionExport_Scheme);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
}
|
}
|
||||||
|
@ -323,3 +331,111 @@ void EditorColorSchemeWidget::on_btnSchemeMenu_pressed()
|
||||||
p.setY(ui->btnSchemeMenu->height()+2);
|
p.setY(ui->btnSchemeMenu->height()+2);
|
||||||
menu.exec(ui->btnSchemeMenu->mapToGlobal(p));
|
menu.exec(ui->btnSchemeMenu->mapToGlobal(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorColorSchemeWidget::on_actionImport_Scheme_triggered()
|
||||||
|
{
|
||||||
|
QString filename = QFileDialog::getOpenFileName(this,
|
||||||
|
tr("Open"), QString(), tr("Color Scheme Files (*.scheme)"));
|
||||||
|
if (filename.isEmpty())
|
||||||
|
return;
|
||||||
|
QFileInfo fileInfo(filename);
|
||||||
|
QString name = fileInfo.fileName();
|
||||||
|
QString suffix = EXT_COLOR_SCHEME;
|
||||||
|
if (!name.toLower().endsWith(suffix))
|
||||||
|
return;
|
||||||
|
name.remove(name.length()-suffix.length(),suffix.length());
|
||||||
|
name.replace('_',' ');
|
||||||
|
if (!pColorManager->isValidName(name)) {
|
||||||
|
QMessageBox::information(this,tr("Error"),tr("'%1' is not a valid name for color scheme file."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PColorScheme scheme = ColorScheme::load(filename);
|
||||||
|
pColorManager->add(name, scheme);
|
||||||
|
ui->cbScheme->addItem(name);
|
||||||
|
ui->cbScheme->setCurrentText(name);
|
||||||
|
} catch (FileError e) {
|
||||||
|
QMessageBox::information(this,tr("Error"),e.reason());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorColorSchemeWidget::on_actionRename_Scheme_triggered()
|
||||||
|
{
|
||||||
|
QString name = ui->cbScheme->currentText();
|
||||||
|
bool isOk;
|
||||||
|
QString newName = QInputDialog::getText(this,tr("New scheme name"),tr("New scheme name"),
|
||||||
|
QLineEdit::Normal,name,&isOk);
|
||||||
|
if (isOk) {
|
||||||
|
if (!pColorManager->isValidName(newName)) {
|
||||||
|
QMessageBox::information(this,tr("Error"),tr("'%1' is not a valid scheme name!").arg(newName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
pColorManager->rename(name,newName);
|
||||||
|
ui->cbScheme->setItemText(
|
||||||
|
ui->cbScheme->currentIndex(),
|
||||||
|
newName
|
||||||
|
);
|
||||||
|
if (mModifiedSchemes.contains(name))
|
||||||
|
mModifiedSchemes.remove(name);
|
||||||
|
mModifiedSchemes.insert(newName);
|
||||||
|
} catch(FileError e) {
|
||||||
|
QMessageBox::information(this,tr("Error"),e.reason());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorColorSchemeWidget::on_actionReset_Scheme_triggered()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (pColorManager->restoreToDefault(ui->cbScheme->currentText())) {
|
||||||
|
ui->cbScheme->setItemData(
|
||||||
|
ui->cbScheme->currentIndex(),
|
||||||
|
QVariant(),
|
||||||
|
Qt::FontRole);
|
||||||
|
ui->cbScheme->setFont(mDefaultSchemeComboFont);
|
||||||
|
//ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
||||||
|
}
|
||||||
|
} catch (FileError e) {
|
||||||
|
QMessageBox::information(this,tr("Error"),e.reason());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorColorSchemeWidget::on_actionExport_Scheme_triggered()
|
||||||
|
{
|
||||||
|
QString filename = QFileDialog::getSaveFileName(this,
|
||||||
|
tr("Save"), QString(), tr("Color Scheme Files (*.scheme)"));
|
||||||
|
if (filename.isEmpty())
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
PColorScheme scheme = getCurrentScheme();
|
||||||
|
scheme->save(filename);
|
||||||
|
} catch (FileError e) {
|
||||||
|
QMessageBox::information(this,tr("Error"),e.reason());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorColorSchemeWidget::on_actionDelete_Scheme_triggered()
|
||||||
|
{
|
||||||
|
|
||||||
|
QString name = ui->cbScheme->currentText();
|
||||||
|
if (QMessageBox::information(this,tr("Confirm Delete Scheme"),
|
||||||
|
tr("Scheme '%1' will be deleted!<br />Do you really want to continue?")
|
||||||
|
.arg(name),
|
||||||
|
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
if (pColorManager->remove(name)) {
|
||||||
|
if (mModifiedSchemes.contains(name))
|
||||||
|
mModifiedSchemes.remove(name);
|
||||||
|
ui->cbScheme->removeItem(ui->cbScheme->currentIndex());
|
||||||
|
if (name == pSettings->editor().colorScheme())
|
||||||
|
doSave();
|
||||||
|
}
|
||||||
|
} catch (FileError e) {
|
||||||
|
QMessageBox::information(this,tr("Error"),e.reason());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,11 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionCopy_Scheme_triggered();
|
void on_actionCopy_Scheme_triggered();
|
||||||
void on_btnSchemeMenu_pressed();
|
void on_btnSchemeMenu_pressed();
|
||||||
|
void on_actionImport_Scheme_triggered();
|
||||||
|
void on_actionRename_Scheme_triggered();
|
||||||
|
void on_actionReset_Scheme_triggered();
|
||||||
|
void on_actionExport_Scheme_triggered();
|
||||||
|
void on_actionDelete_Scheme_triggered();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EDITORCOLORSCHEMEWIDGET_H
|
#endif // EDITORCOLORSCHEMEWIDGET_H
|
||||||
|
|
|
@ -147,11 +147,11 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widgetSchemeItem" native="true">
|
<widget class="QWidget" name="widget_5" native="true">
|
||||||
<property name="enabled">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<bool>true</bool>
|
<property name="spacing">
|
||||||
</property>
|
<number>7</number>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
</property>
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -164,102 +164,154 @@
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="1">
|
<item>
|
||||||
<widget class="QCheckBox" name="cbBackground">
|
<widget class="QWidget" name="widgetSchemeItem" native="true">
|
||||||
<property name="text">
|
<property name="enabled">
|
||||||
<string>Background:</string>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
</item>
|
<property name="leftMargin">
|
||||||
<item row="1" column="1">
|
<number>0</number>
|
||||||
<widget class="QCheckBox" name="cbForeground">
|
</property>
|
||||||
<property name="text">
|
<property name="topMargin">
|
||||||
<string>Foreground:</string>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="rightMargin">
|
||||||
</item>
|
<number>0</number>
|
||||||
<item row="1" column="2">
|
</property>
|
||||||
<widget class="ColorEdit" name="colorForeground">
|
<property name="bottomMargin">
|
||||||
<property name="sizePolicy">
|
<number>0</number>
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
</property>
|
||||||
<horstretch>0</horstretch>
|
<item row="0" column="1">
|
||||||
<verstretch>0</verstretch>
|
<widget class="QCheckBox" name="cbBackground">
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::StyledPanel</enum>
|
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Raised</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="3">
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="ColorEdit" name="colorBackground">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::StyledPanel</enum>
|
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Raised</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QGroupBox" name="grpFontStyles">
|
|
||||||
<property name="title">
|
|
||||||
<string>Font Styles</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="cbBold">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Bold</string>
|
<string>Background:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="1">
|
||||||
<widget class="QCheckBox" name="cbItalic">
|
<widget class="QCheckBox" name="cbForeground">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Italic</string>
|
<string>Foreground:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="2">
|
||||||
<widget class="QCheckBox" name="cbStrikeout">
|
<widget class="ColorEdit" name="colorForeground">
|
||||||
<property name="text">
|
<property name="sizePolicy">
|
||||||
<string>Strikeout</string>
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="0" column="3">
|
||||||
<widget class="QCheckBox" name="cbUnderlined">
|
<spacer name="horizontalSpacer_2">
|
||||||
<property name="text">
|
<property name="orientation">
|
||||||
<string>Underlined</string>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="ColorEdit" name="colorBackground">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget_4" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="grpFontStyles">
|
||||||
|
<property name="title">
|
||||||
|
<string>Font Styles</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cbBold">
|
||||||
|
<property name="text">
|
||||||
|
<string>Bold</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cbItalic">
|
||||||
|
<property name="text">
|
||||||
|
<string>Italic</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cbStrikeout">
|
||||||
|
<property name="text">
|
||||||
|
<string>Strikeout</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cbUnderlined">
|
||||||
|
<property name="text">
|
||||||
|
<string>Underlined</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -94,7 +94,6 @@ QString TrimLeft(const QString& s);
|
||||||
bool StringIsBlank(const QString& s);
|
bool StringIsBlank(const QString& s);
|
||||||
|
|
||||||
void changeTheme(const QString& themeName);
|
void changeTheme(const QString& themeName);
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
class final_action
|
class final_action
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
ColorEdit::ColorEdit(QWidget *parent):QFrame(parent)
|
ColorEdit::ColorEdit(QWidget *parent):QFrame(parent)
|
||||||
{
|
{
|
||||||
|
@ -21,13 +22,18 @@ void ColorEdit::setColor(const QColor &value)
|
||||||
if (mColor!=value) {
|
if (mColor!=value) {
|
||||||
mColor=value;
|
mColor=value;
|
||||||
emit colorChanged(value);
|
emit colorChanged(value);
|
||||||
update();
|
resize(sizeHint());
|
||||||
|
// update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor ColorEdit::contrast()
|
QColor ColorEdit::contrast()
|
||||||
{
|
{
|
||||||
int crBg = mColor.rgb() & 0xFFFFFF;
|
int crBg;
|
||||||
|
if (!mColor.isValid())
|
||||||
|
crBg = palette().color(QPalette::Base).rgb() & 0xFFFFFF;
|
||||||
|
else
|
||||||
|
crBg = mColor.rgb() & 0xFFFFFF;
|
||||||
int TOLERANCE = 30;
|
int TOLERANCE = 30;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
@ -44,18 +50,32 @@ QColor ColorEdit::contrast()
|
||||||
|
|
||||||
QSize ColorEdit::sizeHint() const
|
QSize ColorEdit::sizeHint() const
|
||||||
{
|
{
|
||||||
QRect rect = fontMetrics().boundingRect(mColor.name());
|
QRect rect;
|
||||||
|
if (mColor.isValid() )
|
||||||
|
rect = fontMetrics().boundingRect(mColor.name());
|
||||||
|
else
|
||||||
|
rect = fontMetrics().boundingRect(tr("NONE"));
|
||||||
return QSize{rect.width()+ 10,
|
return QSize{rect.width()+ 10,
|
||||||
rect.height()+ 6 };
|
rect.height()+ 6 };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorEdit::paintEvent(QPaintEvent *event)
|
void ColorEdit::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QRect rect = QRect(lineWidth(),lineWidth(),width()-2*lineWidth(),height()-2*lineWidth());
|
QRect rect = QRect(lineWidth(),lineWidth(),width()-2*lineWidth(),height()-2*lineWidth());
|
||||||
painter.fillRect(rect,mColor);
|
if (mColor.isValid()) {
|
||||||
painter.setPen(contrast());
|
//painter.fillRect(rect,mColor);
|
||||||
painter.drawText(rect,Qt::AlignCenter, mColor.name());
|
painter.setPen(contrast());
|
||||||
|
painter.setBrush(mColor);
|
||||||
|
painter.drawRect(rect);
|
||||||
|
painter.drawText(rect,Qt::AlignCenter, mColor.name());
|
||||||
|
} else {
|
||||||
|
//painter.fillRect(rect,palette().color(QPalette::Base));
|
||||||
|
painter.setPen(contrast());
|
||||||
|
painter.setBrush(palette().color(QPalette::Base));
|
||||||
|
painter.drawRect(rect);
|
||||||
|
painter.drawText(rect,Qt::AlignCenter, tr("NONE"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorEdit::mouseReleaseEvent(QMouseEvent *event)
|
void ColorEdit::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
@ -78,7 +98,5 @@ void ColorEdit::leaveEvent(QEvent *event)
|
||||||
|
|
||||||
QSize ColorEdit::minimumSizeHint() const
|
QSize ColorEdit::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
QRect rect = fontMetrics().boundingRect(mColor.name());
|
return sizeHint();
|
||||||
return QSize{rect.width(),
|
|
||||||
rect.height()};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue