Compare commits
8 Commits
b9dea57200
...
6a67442d21
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a67442d21 | |||
| 8feb5c240c | |||
| 64f3448b5c | |||
| a93db66d78 | |||
| 071a73f5ba | |||
| 2739cc53ec | |||
| ccf17510d8 | |||
| e0134b3b5e |
@@ -6,11 +6,6 @@
|
|||||||
|
|
||||||
|
|
||||||
Ribbon::Ribbon(QMainWindow * parent_): QToolBar() {
|
Ribbon::Ribbon(QMainWindow * parent_): QToolBar() {
|
||||||
tab = 0;
|
|
||||||
scroll_area = 0;
|
|
||||||
delay_e = true;
|
|
||||||
delay = 1000;
|
|
||||||
hovered = -1;
|
|
||||||
setObjectName("ribbon");
|
setObjectName("ribbon");
|
||||||
setProperty("ribbon", true);
|
setProperty("ribbon", true);
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
@@ -67,8 +62,8 @@ void Ribbon::_resize() {
|
|||||||
|
|
||||||
void Ribbon::_setIconsSize() {
|
void Ribbon::_setIconsSize() {
|
||||||
// qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
// qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||||
setTabIconSize(preferredIconSize(2, this));
|
setTabIconSize(preferredIconSize(1.6, this));
|
||||||
setIconSize(preferredIconSize(3, this));
|
setIconSize(preferredIconSize(2.4, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,6 +77,14 @@ void Ribbon::_setButtonText(QToolButton * b, QAction * a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Ribbon::tabHovered(int tab) {
|
||||||
|
if (!delay_e) return;
|
||||||
|
hovers.clear();
|
||||||
|
hovered = tab;
|
||||||
|
hovers.insert(startTimer(delay), tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Ribbon::setVisible(bool yes) {
|
void Ribbon::setVisible(bool yes) {
|
||||||
QToolBar::setVisible(yes);
|
QToolBar::setVisible(yes);
|
||||||
if (parent == 0) return;
|
if (parent == 0) return;
|
||||||
@@ -250,3 +253,15 @@ void Ribbon::setTabIconSize(const QSize & size) {
|
|||||||
#endif
|
#endif
|
||||||
_resize();
|
_resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Ribbon::setButtonStyle(const Qt::ToolButtonStyle & style) {
|
||||||
|
foreach(QToolButton * i, buttons)
|
||||||
|
i->setToolButtonStyle(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Ribbon::setCurrentTab(int tab_) {
|
||||||
|
if (tab_ < 0 || tab_ >= tab->count()) return;
|
||||||
|
tab->setCurrentIndex(tab_);
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,16 +46,10 @@ public:
|
|||||||
void retranslate();
|
void retranslate();
|
||||||
void setIconSize(const QSize & size);
|
void setIconSize(const QSize & size);
|
||||||
void setTabIconSize(const QSize & size);
|
void setTabIconSize(const QSize & size);
|
||||||
void setButtonStyle(const Qt::ToolButtonStyle & style) {
|
void setButtonStyle(const Qt::ToolButtonStyle & style);
|
||||||
foreach(QToolButton * i, buttons)
|
|
||||||
i->setToolButtonStyle(style);
|
|
||||||
}
|
|
||||||
void setAutoSwitchEnabled(bool yes) { delay_e = yes; }
|
void setAutoSwitchEnabled(bool yes) { delay_e = yes; }
|
||||||
void setAutoSwitchDelay(float delay_s) { delay = delay_s * 1000; }
|
void setAutoSwitchDelay(float delay_s) { delay = delay_s * 1000; }
|
||||||
void setCurrentTab(int tab_) {
|
void setCurrentTab(int tab_);
|
||||||
if (tab_ < 0 || tab_ >= tab->count()) return;
|
|
||||||
tab->setCurrentIndex(tab_);
|
|
||||||
}
|
|
||||||
int currentTab() const { return tab->currentIndex(); }
|
int currentTab() const { return tab->currentIndex(); }
|
||||||
QTabWidget * tabWidget() const { return tab; }
|
QTabWidget * tabWidget() const { return tab; }
|
||||||
|
|
||||||
@@ -67,21 +61,16 @@ private:
|
|||||||
void _setIconsSize();
|
void _setIconsSize();
|
||||||
void _setButtonText(QToolButton * b, QAction * a);
|
void _setButtonText(QToolButton * b, QAction * a);
|
||||||
|
|
||||||
int hovered, delay;
|
int hovered = -1, delay = 1000;
|
||||||
bool delay_e;
|
bool delay_e = true;
|
||||||
QList<QToolButton *> buttons;
|
QList<QToolButton *> buttons;
|
||||||
QMap<int, int> hovers;
|
QMap<int, int> hovers;
|
||||||
ETabWidget * tab;
|
ETabWidget * tab = nullptr;
|
||||||
QScrollArea * scroll_area;
|
QScrollArea * scroll_area = nullptr;
|
||||||
QMainWindow * parent;
|
QMainWindow * parent = nullptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void tabHovered(int tab) {
|
void tabHovered(int tab);
|
||||||
if (!delay_e) return;
|
|
||||||
hovers.clear();
|
|
||||||
hovered = tab;
|
|
||||||
hovers.insert(startTimer(delay), tab);
|
|
||||||
}
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setVisible(bool yes);
|
void setVisible(bool yes);
|
||||||
|
|||||||
@@ -150,6 +150,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widgetAlign9" native="true">
|
<widget class="QWidget" name="widgetAlign9" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
@@ -777,9 +783,15 @@
|
|||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>4</number>
|
<number>4</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="verticalSpacing">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QCheckBox" name="checkVLEnabled">
|
<widget class="QCheckBox" name="checkVLEnabled">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -886,6 +898,7 @@
|
|||||||
<class>IconedLabel</class>
|
<class>IconedLabel</class>
|
||||||
<extends>QFrame</extends>
|
<extends>QFrame</extends>
|
||||||
<header>iconedlabel.h</header>
|
<header>iconedlabel.h</header>
|
||||||
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
|||||||
qRegisterMetaType<QTextCursor>();
|
qRegisterMetaType<QTextCursor>();
|
||||||
qRegisterMetaType<QCodeEdit::ACEntry>();
|
qRegisterMetaType<QCodeEdit::ACEntry>();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
detectTheme();
|
||||||
overlay = new _QCE_Viewport(ui->textCode->viewport());
|
overlay = new _QCE_Viewport(ui->textCode->viewport());
|
||||||
overlay->ce = this;
|
overlay->ce = this;
|
||||||
overlay->show();
|
overlay->show();
|
||||||
@@ -548,6 +549,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void QCodeEdit::showEvent(QShowEvent *) {
|
void QCodeEdit::showEvent(QShowEvent *) {
|
||||||
|
detectTheme();
|
||||||
if (!_first) return;
|
if (!_first) return;
|
||||||
_first = false;
|
_first = false;
|
||||||
completer->installEventFilter(this);
|
completer->installEventFilter(this);
|
||||||
@@ -584,6 +586,7 @@ void QCodeEdit::changeEvent(QEvent * e) {
|
|||||||
ui->retranslateUi(this);
|
ui->retranslateUi(this);
|
||||||
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
||||||
break;
|
break;
|
||||||
|
case QEvent::PaletteChange: detectTheme(); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -875,9 +878,36 @@ void QCodeEdit::highlightBrackets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QColor inverseColorValue(const QColor & c) {
|
||||||
|
int hsv[4];
|
||||||
|
c.getHsl(&hsv[0], &hsv[1], &hsv[2], &hsv[3]);
|
||||||
|
return QColor::fromHsl(hsv[0], hsv[1], 255 - hsv[2], hsv[3]);
|
||||||
|
}
|
||||||
|
QBrush QCodeEdit::invertedBrush(const QBrush & b) {
|
||||||
|
auto ret = b;
|
||||||
|
ret.setColor(inverseColorValue(b.color()));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QTextCharFormat QCodeEdit::invertedFormat(const QTextCharFormat & f) {
|
||||||
|
auto ret = f;
|
||||||
|
ret.setForeground(invertedBrush(ret.foreground()));
|
||||||
|
ret.setBackground(invertedBrush(ret.background()));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QCodeEdit::applyExtraSelection() {
|
void QCodeEdit::applyExtraSelection() {
|
||||||
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected << es_custom << es_brackets
|
QList<QTextEdit::ExtraSelection> esl;
|
||||||
<< es_search_list << es_cursor << es_link << es_blockselection);
|
esl << es_line << es_selected << es_custom << es_brackets << es_search_list << es_cursor << es_link;
|
||||||
|
if (is_dark_theme) {
|
||||||
|
for (auto & e: esl) {
|
||||||
|
e.format = invertedFormat(e.format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
esl << es_blockselection;
|
||||||
|
ui->textCode->setExtraSelections(esl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1702,6 +1732,11 @@ QCodeEdit::ACEntry QCodeEdit::findEntryOnCursor(QTextCursor tc, int arg, ACClass
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QCodeEdit::detectTheme() {
|
||||||
|
is_dark_theme = palette().color(QPalette::Window).valueF() < 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QCodeEdit::raiseHelp(QTextCursor tc, int arg) {
|
void QCodeEdit::raiseHelp(QTextCursor tc, int arg) {
|
||||||
ACClass acc;
|
ACClass acc;
|
||||||
QPair<QStringList, QString> scope;
|
QPair<QStringList, QString> scope;
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ public:
|
|||||||
|
|
||||||
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon());
|
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon());
|
||||||
bool wordCompletitionEnabled() const { return word_complete; }
|
bool wordCompletitionEnabled() const { return word_complete; }
|
||||||
|
bool isDarkTheme() const { return is_dark_theme; }
|
||||||
|
|
||||||
|
static QBrush invertedBrush(const QBrush & b);
|
||||||
|
static QTextCharFormat invertedFormat(const QTextCharFormat & f);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef QPair<QString, QString> StringsPair;
|
typedef QPair<QString, QString> StringsPair;
|
||||||
@@ -230,6 +234,7 @@ private:
|
|||||||
void createBlockSelection();
|
void createBlockSelection();
|
||||||
void cancelDragCursor();
|
void cancelDragCursor();
|
||||||
ACEntry findEntryOnCursor(QTextCursor tc, int arg = -1, ACClass * acc = nullptr, QPair<QStringList, QString> * scope = nullptr);
|
ACEntry findEntryOnCursor(QTextCursor tc, int arg = -1, ACClass * acc = nullptr, QPair<QStringList, QString> * scope = nullptr);
|
||||||
|
void detectTheme();
|
||||||
|
|
||||||
Ui::QCodeEdit * ui;
|
Ui::QCodeEdit * ui;
|
||||||
QCodeEditCompleter * completer;
|
QCodeEditCompleter * completer;
|
||||||
@@ -245,6 +250,7 @@ private:
|
|||||||
QTextCursor block_start_cursor, drag_cursor;
|
QTextCursor block_start_cursor, drag_cursor;
|
||||||
int prev_lc, auto_comp_pl, timer_parse, timer_blink, cur_search_ind, pos_press, pos_el_press;
|
int prev_lc, auto_comp_pl, timer_parse, timer_blink, cur_search_ind, pos_press, pos_el_press;
|
||||||
int cursor_width;
|
int cursor_width;
|
||||||
|
bool is_dark_theme = false;
|
||||||
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
|
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
|
||||||
bool word_complete, help_visible, cursor_state, block_sel_state;
|
bool word_complete, help_visible, cursor_state, block_sel_state;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void QCodeEditCompleter::addItems(QFont f, const QCodeEdit::ACClass & cl, const
|
|||||||
gi->setTextAlignment(0, Qt::AlignCenter);
|
gi->setTextAlignment(0, Qt::AlignCenter);
|
||||||
gi->setTextAlignment(1, Qt::AlignCenter);
|
gi->setTextAlignment(1, Qt::AlignCenter);
|
||||||
gi->setFont(0, f);
|
gi->setFont(0, f);
|
||||||
gi->setBackground(0, Qt::lightGray);
|
gi->setBackground(0, palette().window());
|
||||||
gi->setFlags(Qt::ItemIsEnabled);
|
gi->setFlags(Qt::ItemIsEnabled);
|
||||||
addTopLevelItem(gi);
|
addTopLevelItem(gi);
|
||||||
gi->setFirstColumnSpanned(true);
|
gi->setFirstColumnSpanned(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user