Skip to content

Commit

Permalink
feat: DTK-changed consolewidget
Browse files Browse the repository at this point in the history
Dtk-changed and consoleWidget backgroundColor changes with system theme
  • Loading branch information
LiHua000 committed Nov 23, 2023
1 parent ca27ed7 commit c7feb35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
29 changes: 24 additions & 5 deletions src/plugins/console/consolewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "consolewidget.h"

#include <DMenu>

#include <QDebug>
#include <QMenu>

DWIDGET_USE_NAMESPACE

static ConsoleWidget *ins{nullptr};

class ConsoleWidgetPrivate
{
public:
QMenu *menu = nullptr;
DMenu *menu = nullptr;
QAction *consoleCopy = nullptr;
QAction *consolePaste = nullptr;
};
Expand All @@ -30,10 +35,13 @@ ConsoleWidget::ConsoleWidget(QWidget *parent)
setTerminalOpacity(0);
setForegroundRole(QPalette::ColorRole::Window);
setAutoFillBackground(true);
if (availableColorSchemes().contains("Linux"))
setColorScheme("Linux");
setTerminalOpacity(1);

auto theme = DGuiApplicationHelper::instance()->themeType();
updateColorScheme(theme);
if (availableKeyBindings().contains("linux"))
setKeyBindings("linux");

setScrollBarPosition(QTermWidget::ScrollBarRight);
setTerminalSizeHint(false);
setAutoClose(false);
Expand All @@ -44,6 +52,8 @@ ConsoleWidget::ConsoleWidget(QWidget *parent)
d->consolePaste = new QAction(tr("paste"));
QObject::connect(d->consoleCopy, &QAction::triggered, this, &QTermWidget::copyClipboard);
QObject::connect(d->consolePaste, &QAction::triggered, this, &QTermWidget::pasteClipboard);
QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged,
this, &ConsoleWidget::updateTheme);
}

ConsoleWidget::~ConsoleWidget()
Expand All @@ -54,7 +64,7 @@ ConsoleWidget::~ConsoleWidget()
void ConsoleWidget::contextMenuEvent(QContextMenuEvent *event)
{
if (nullptr == d->menu) {
d->menu = new QMenu(this);
d->menu = new DMenu(this);
d->menu->setParent(this);
d->menu->addAction(d->consoleCopy);
d->menu->addAction(d->consolePaste);
Expand All @@ -66,3 +76,12 @@ void ConsoleWidget::contextMenuEvent(QContextMenuEvent *event)
}
d->menu->exec(event->globalPos());
}

void ConsoleWidget::updateColorScheme(DGuiApplicationHelper::ColorType themetype)
{
if (themetype == DGuiApplicationHelper::DarkType
&& availableColorSchemes().contains("Linux"))
this->setColorScheme("Linux");
else if (availableColorSchemes().contains("BlackOnWhite"))
this->setColorScheme("BlackOnWhite");
}
5 changes: 4 additions & 1 deletion src/plugins/console/consolewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include "qtermwidget.h" // 3drparty
#include "ColorScheme.h"

#include <DGuiApplicationHelper>

#include <QDir>
DGUI_USE_NAMESPACE

class ConsoleWidgetPrivate;
class ConsoleWidget : public QTermWidget
Expand All @@ -21,7 +24,7 @@ class ConsoleWidget : public QTermWidget

protected:
void contextMenuEvent(QContextMenuEvent *event);

void updateColorScheme(DGuiApplicationHelper::ColorType themetype);
private:
ConsoleWidgetPrivate *const d;
};
Expand Down

0 comments on commit c7feb35

Please sign in to comment.