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() {
|
||||
tab = 0;
|
||||
scroll_area = 0;
|
||||
delay_e = true;
|
||||
delay = 1000;
|
||||
hovered = -1;
|
||||
setObjectName("ribbon");
|
||||
setProperty("ribbon", true);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
@@ -67,8 +62,8 @@ void Ribbon::_resize() {
|
||||
|
||||
void Ribbon::_setIconsSize() {
|
||||
// qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
setTabIconSize(preferredIconSize(2, this));
|
||||
setIconSize(preferredIconSize(3, this));
|
||||
setTabIconSize(preferredIconSize(1.6, 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) {
|
||||
QToolBar::setVisible(yes);
|
||||
if (parent == 0) return;
|
||||
@@ -250,3 +253,15 @@ void Ribbon::setTabIconSize(const QSize & size) {
|
||||
#endif
|
||||
_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 setIconSize(const QSize & size);
|
||||
void setTabIconSize(const QSize & size);
|
||||
void setButtonStyle(const Qt::ToolButtonStyle & style) {
|
||||
foreach(QToolButton * i, buttons)
|
||||
i->setToolButtonStyle(style);
|
||||
}
|
||||
void setButtonStyle(const Qt::ToolButtonStyle & style);
|
||||
void setAutoSwitchEnabled(bool yes) { delay_e = yes; }
|
||||
void setAutoSwitchDelay(float delay_s) { delay = delay_s * 1000; }
|
||||
void setCurrentTab(int tab_) {
|
||||
if (tab_ < 0 || tab_ >= tab->count()) return;
|
||||
tab->setCurrentIndex(tab_);
|
||||
}
|
||||
void setCurrentTab(int tab_);
|
||||
int currentTab() const { return tab->currentIndex(); }
|
||||
QTabWidget * tabWidget() const { return tab; }
|
||||
|
||||
@@ -67,21 +61,16 @@ private:
|
||||
void _setIconsSize();
|
||||
void _setButtonText(QToolButton * b, QAction * a);
|
||||
|
||||
int hovered, delay;
|
||||
bool delay_e;
|
||||
int hovered = -1, delay = 1000;
|
||||
bool delay_e = true;
|
||||
QList<QToolButton *> buttons;
|
||||
QMap<int, int> hovers;
|
||||
ETabWidget * tab;
|
||||
QScrollArea * scroll_area;
|
||||
QMainWindow * parent;
|
||||
ETabWidget * tab = nullptr;
|
||||
QScrollArea * scroll_area = nullptr;
|
||||
QMainWindow * parent = nullptr;
|
||||
|
||||
private slots:
|
||||
void tabHovered(int tab) {
|
||||
if (!delay_e) return;
|
||||
hovers.clear();
|
||||
hovered = tab;
|
||||
hovers.insert(startTimer(delay), tab);
|
||||
}
|
||||
void tabHovered(int tab);
|
||||
|
||||
public slots:
|
||||
void setVisible(bool yes);
|
||||
|
||||
@@ -150,6 +150,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widgetAlign9" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
@@ -777,9 +783,15 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkVLEnabled">
|
||||
<property name="text">
|
||||
@@ -886,6 +898,7 @@
|
||||
<class>IconedLabel</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>iconedlabel.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
|
||||
@@ -54,6 +54,7 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
||||
qRegisterMetaType<QTextCursor>();
|
||||
qRegisterMetaType<QCodeEdit::ACEntry>();
|
||||
ui->setupUi(this);
|
||||
detectTheme();
|
||||
overlay = new _QCE_Viewport(ui->textCode->viewport());
|
||||
overlay->ce = this;
|
||||
overlay->show();
|
||||
@@ -548,6 +549,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
|
||||
|
||||
void QCodeEdit::showEvent(QShowEvent *) {
|
||||
detectTheme();
|
||||
if (!_first) return;
|
||||
_first = false;
|
||||
completer->installEventFilter(this);
|
||||
@@ -584,6 +586,7 @@ void QCodeEdit::changeEvent(QEvent * e) {
|
||||
ui->retranslateUi(this);
|
||||
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
||||
break;
|
||||
case QEvent::PaletteChange: detectTheme(); 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() {
|
||||
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected << es_custom << es_brackets
|
||||
<< es_search_list << es_cursor << es_link << es_blockselection);
|
||||
QList<QTextEdit::ExtraSelection> esl;
|
||||
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) {
|
||||
ACClass acc;
|
||||
QPair<QStringList, QString> scope;
|
||||
|
||||
@@ -110,6 +110,10 @@ public:
|
||||
|
||||
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon());
|
||||
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:
|
||||
typedef QPair<QString, QString> StringsPair;
|
||||
@@ -230,6 +234,7 @@ private:
|
||||
void createBlockSelection();
|
||||
void cancelDragCursor();
|
||||
ACEntry findEntryOnCursor(QTextCursor tc, int arg = -1, ACClass * acc = nullptr, QPair<QStringList, QString> * scope = nullptr);
|
||||
void detectTheme();
|
||||
|
||||
Ui::QCodeEdit * ui;
|
||||
QCodeEditCompleter * completer;
|
||||
@@ -245,6 +250,7 @@ private:
|
||||
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 cursor_width;
|
||||
bool is_dark_theme = false;
|
||||
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
|
||||
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(1, Qt::AlignCenter);
|
||||
gi->setFont(0, f);
|
||||
gi->setBackground(0, Qt::lightGray);
|
||||
gi->setBackground(0, palette().window());
|
||||
gi->setFlags(Qt::ItemIsEnabled);
|
||||
addTopLevelItem(gi);
|
||||
gi->setFirstColumnSpanned(true);
|
||||
|
||||
Reference in New Issue
Block a user