Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
FrmParameterTerminalAppearanceSettings.cpp
1#include "FrmParameterTerminalAppearanceSettings.h"
2#include "ui_FrmParameterTerminalAppearanceSettings.h"
3#include "RabbitCommonDir.h"
4#include "qtermwidget.h"
5
6#include "RabbitCommonDir.h"
7
8#include <QCoreApplication>
9#include <QLocale>
10#include <QDebug>
11#include <QTranslator>
12#include <QFont>
13#include <QLoggingCategory>
14
15Q_DECLARE_LOGGING_CATEGORY(Terminal)
16
18{
19public:
20 CTerminal()
21 {
22 QString szTranslatorFile = RabbitCommon::CDir::Instance()->GetDirTranslations()
23 + QDir::separator() + "Terminal_" + QLocale::system().name() + ".qm";
24 if(!m_Translator.load(szTranslatorFile))
25 qCritical(Terminal) << "Open translator file fail:" << szTranslatorFile;
26 qApp->installTranslator(&m_Translator);
27 };
28
30 {
31 qApp->removeTranslator(&m_Translator);
32 qDebug(Terminal) << "CTerminal::~CTerminal()";
33 };
34
35private:
36 QTranslator m_Translator;
37};
38
39const CTerminal g_CTerminal;
40
41CFrmParameterTerminalAppearanceSettings::CFrmParameterTerminalAppearanceSettings(CParameterTerminal *pPara, QWidget *parent) :
42 QWidget(parent),
44 m_pPara(pPara)
45{
46 ui->setupUi(this);
47
48 Q_ASSERT(pPara);
49 if(!pPara) return;
50
51 QFont f = pPara->GetFont();
52 ui->spFontSize->setValue(f.pointSize());
53 ui->lbFont->setFont(f);
54
55 ui->fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts
56 | QFontComboBox::NonScalableFonts
57 | QFontComboBox::ScalableFonts);
58 ui->fontComboBox->setCurrentFont(f);
59 ui->fontComboBox->setEditable(false);
60
61 ui->cbShowResize->setChecked(pPara->GetSizeHint());
62
63 ui->cbCursorShape->addItem(tr("BlockCursor"), (int)Konsole::Emulation::KeyboardCursorShape::BlockCursor);
64 ui->cbCursorShape->addItem(tr("UnderlineCursor"), (int)Konsole::Emulation::KeyboardCursorShape::UnderlineCursor);
65 ui->cbCursorShape->addItem(tr("IBeamCursor"), (int)Konsole::Emulation::KeyboardCursorShape::BlockCursor);
66 ui->cbCursorShape->setCurrentIndex((int)pPara->GetCursorShape());
67
68 ui->cbColorScheme->addItems(QTermWidget::availableColorSchemes());
69 if(!m_pPara->GetColorScheme().isEmpty())
70 ui->cbColorScheme->setCurrentText(pPara->GetColorScheme());
71
72 ui->cbScrollBarPositioin->addItem(tr("No"), QTermWidget::NoScrollBar);
73 ui->cbScrollBarPositioin->addItem(tr("Left"), QTermWidget::ScrollBarLeft);
74 ui->cbScrollBarPositioin->addItem(tr("Right"), QTermWidget::ScrollBarRight);
75 ui->cbScrollBarPositioin->setCurrentIndex(pPara->GetScrollBarPosition());
76
77 ui->spTerminalTransparecy->setValue(pPara->GetTransparency());
78 ui->cbFlowControl->setChecked(m_pPara->GetFlowControl());
79 ui->cbBiDirectional->setChecked(m_pPara->GetDirectional());
80 ui->leImage->setText(m_pPara->GetBackgroupImage());
81}
82
83CFrmParameterTerminalAppearanceSettings::~CFrmParameterTerminalAppearanceSettings()
84{
85 delete ui;
86}
87
88void CFrmParameterTerminalAppearanceSettings::on_fontComboBox_currentFontChanged(const QFont &f)
89{
90 QFont font = f;
91 font.setPointSize(ui->spFontSize->value());
92 ui->lbFont->setFont(font);
93 ui->lbFont->setText(tr("Example: Display font"));
94}
95
96void CFrmParameterTerminalAppearanceSettings::on_spFontSize_valueChanged(int size)
97{
98 QFont font = ui->fontComboBox->currentFont();
99 font.setPointSize(size);
100 ui->lbFont->setFont(font);
101 ui->lbFont->setText(tr("Example: Display font"));
102}
103
104int CFrmParameterTerminalAppearanceSettings::AcceptSettings()
105{
106 if(!m_pPara) return -1;
107 m_pPara->SetFont(ui->fontComboBox->currentFont());
108 QFont font = m_pPara->GetFont();
109 font.setPointSize(ui->spFontSize->value());
110 m_pPara->SetFont(font);
111 m_pPara->SetSizeHint(ui->cbShowResize->isChecked());
112 m_pPara->SetColorScheme(ui->cbColorScheme->currentText());
113 m_pPara->SetCursorShape(static_cast<Konsole::Emulation::KeyboardCursorShape>(ui->cbCursorShape->currentData().toInt()));
114 m_pPara->SetScrollBarPosition(static_cast<QTermWidget::ScrollBarPosition>(ui->cbScrollBarPositioin->currentData().toInt()));
115 m_pPara->SetTransparency(ui->spTerminalTransparecy->value());
116 m_pPara->SetFlowControl(ui->cbFlowControl->isChecked());
117 m_pPara->SetBackgroupImage(ui->leImage->text());
118 m_pPara->SetDirectional(ui->cbBiDirectional->isChecked());
119 return 0;
120}
121
122void CFrmParameterTerminalAppearanceSettings::on_pbBrowser_clicked()
123{
124 QString file = QFileDialog::getOpenFileName(this,
125 tr("Backgroup image"), QString(),
126 tr("Images (*.png *.xpm *.jpg *.bmp *.jpeg);;All files (*.*)"));
127 if(!file.isEmpty())
128 ui->leImage->setText(file);
129}