mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
add settings dialog and language setting
Add VSettingsDialog to show a settings dialog. For now, VNote supports setting of language. Add imcomplete Chinese support. Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
65b149e182
commit
c83fcf6ce9
143
src/dialog/vsettingsdialog.cpp
Normal file
143
src/dialog/vsettingsdialog.cpp
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
#include "vsettingsdialog.h"
|
||||||
|
#include <QtWidgets>
|
||||||
|
#include "vconfigmanager.h"
|
||||||
|
#include "utils/vutils.h"
|
||||||
|
|
||||||
|
extern VConfigManager vconfig;
|
||||||
|
|
||||||
|
VSettingsDialog::VSettingsDialog(QWidget *p_parent)
|
||||||
|
: QDialog(p_parent)
|
||||||
|
{
|
||||||
|
m_tabs = new QTabWidget;
|
||||||
|
m_tabs->addTab(new VGeneralTab(), tr("General"));
|
||||||
|
|
||||||
|
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
connect(m_btnBox, &QDialogButtonBox::accepted, this, &VSettingsDialog::saveConfiguration);
|
||||||
|
connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
|
mainLayout->addWidget(m_tabs);
|
||||||
|
mainLayout->addWidget(m_btnBox);
|
||||||
|
setLayout(mainLayout);
|
||||||
|
|
||||||
|
setWindowTitle(tr("Settings"));
|
||||||
|
|
||||||
|
loadConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VSettingsDialog::loadConfiguration()
|
||||||
|
{
|
||||||
|
// General Tab.
|
||||||
|
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
|
||||||
|
Q_ASSERT(generalTab);
|
||||||
|
bool ret = generalTab->loadConfiguration();
|
||||||
|
if (!ret) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
err:
|
||||||
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
|
QString("Failed to load configuration."), "",
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok, NULL);
|
||||||
|
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VSettingsDialog::saveConfiguration()
|
||||||
|
{
|
||||||
|
// General Tab.
|
||||||
|
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
|
||||||
|
Q_ASSERT(generalTab);
|
||||||
|
bool ret = generalTab->saveConfiguration();
|
||||||
|
if (!ret) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
accept();
|
||||||
|
return;
|
||||||
|
err:
|
||||||
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
|
QString("Failed to save configuration. Please try it again."), "",
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QVector<QString> VGeneralTab::c_availableLangs = { "System", "English", "Chinese" };
|
||||||
|
|
||||||
|
VGeneralTab::VGeneralTab(QWidget *p_parent)
|
||||||
|
: QWidget(p_parent), m_langChanged(false)
|
||||||
|
{
|
||||||
|
QLabel *langLabel = new QLabel(tr("Language:"));
|
||||||
|
m_langCombo = new QComboBox(this);
|
||||||
|
m_langCombo->addItem(tr("System"), "System");
|
||||||
|
auto langs = VUtils::getAvailableLanguages();
|
||||||
|
for (auto lang : langs) {
|
||||||
|
m_langCombo->addItem(lang.second, lang.first);
|
||||||
|
}
|
||||||
|
connect(m_langCombo, SIGNAL(currentIndexChanged(int)),
|
||||||
|
this, SLOT(handleIndexChange(int)));
|
||||||
|
|
||||||
|
QFormLayout *optionLayout = new QFormLayout();
|
||||||
|
optionLayout->addRow(langLabel, m_langCombo);
|
||||||
|
|
||||||
|
QVBoxLayout *mainLayout = new QVBoxLayout();
|
||||||
|
mainLayout->addLayout(optionLayout);
|
||||||
|
|
||||||
|
setLayout(mainLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VGeneralTab::loadConfiguration()
|
||||||
|
{
|
||||||
|
if (!loadLanguage()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VGeneralTab::saveConfiguration()
|
||||||
|
{
|
||||||
|
if (!saveLanguage()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VGeneralTab::loadLanguage()
|
||||||
|
{
|
||||||
|
QString lang = vconfig.getLanguage();
|
||||||
|
if (lang.isNull()) {
|
||||||
|
return false;
|
||||||
|
} else if (lang == "System") {
|
||||||
|
m_langCombo->setCurrentIndex(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool found = false;
|
||||||
|
// Lang is the value, not name.
|
||||||
|
for (int i = 0; i < m_langCombo->count(); ++i) {
|
||||||
|
if (m_langCombo->itemData(i).toString() == lang) {
|
||||||
|
found = true;
|
||||||
|
m_langCombo->setCurrentIndex(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
qWarning() << "invalid language configuration (use default value)";
|
||||||
|
m_langCombo->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VGeneralTab::saveLanguage()
|
||||||
|
{
|
||||||
|
if (m_langChanged) {
|
||||||
|
vconfig.setLanguage(m_langCombo->currentData().toString());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VGeneralTab::handleIndexChange(int p_index)
|
||||||
|
{
|
||||||
|
if (p_index == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_langChanged = true;
|
||||||
|
}
|
51
src/dialog/vsettingsdialog.h
Normal file
51
src/dialog/vsettingsdialog.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef VSETTINGSDIALOG_H
|
||||||
|
#define VSETTINGSDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class QDialogButtonBox;
|
||||||
|
class QTabWidget;
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
|
class VGeneralTab : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit VGeneralTab(QWidget *p_parent = 0);
|
||||||
|
bool loadConfiguration();
|
||||||
|
bool saveConfiguration();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handleIndexChange(int p_index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool loadLanguage();
|
||||||
|
bool saveLanguage();
|
||||||
|
|
||||||
|
// Language
|
||||||
|
QComboBox *m_langCombo;
|
||||||
|
// Whether language changes.
|
||||||
|
bool m_langChanged;
|
||||||
|
|
||||||
|
static const QVector<QString> c_availableLangs;
|
||||||
|
};
|
||||||
|
|
||||||
|
class VSettingsDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit VSettingsDialog(QWidget *p_parent = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void saveConfiguration();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadConfiguration();
|
||||||
|
|
||||||
|
QTabWidget *m_tabs;
|
||||||
|
QDialogButtonBox *m_btnBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VSETTINGSDIALOG_H
|
27
src/main.cpp
27
src/main.cpp
@ -1,9 +1,15 @@
|
|||||||
#include "vmainwindow.h"
|
#include "vmainwindow.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QTranslator>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QLibraryInfo>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
#include "vsingleinstanceguard.h"
|
#include "vsingleinstanceguard.h"
|
||||||
|
#include "vconfigmanager.h"
|
||||||
|
|
||||||
|
VConfigManager vconfig;
|
||||||
|
|
||||||
void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
{
|
{
|
||||||
@ -37,6 +43,27 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
vconfig.initialize();
|
||||||
|
|
||||||
|
QString locale = vconfig.getLanguage();
|
||||||
|
if (locale == "System" || !VUtils::isValidLanguage(locale)) {
|
||||||
|
locale = QLocale::system().name();
|
||||||
|
}
|
||||||
|
qDebug() << "use locale" << locale;
|
||||||
|
|
||||||
|
// load translation for Qt
|
||||||
|
QTranslator qtTranslator;
|
||||||
|
if (!qtTranslator.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
|
||||||
|
qtTranslator.load("qt_" + locale, "translations");
|
||||||
|
}
|
||||||
|
app.installTranslator(&qtTranslator);
|
||||||
|
|
||||||
|
// load translation for vnote
|
||||||
|
QTranslator translator;
|
||||||
|
if (translator.load("vnote_" + locale, ":/translations")) {
|
||||||
|
qDebug() << "install VNote translator";
|
||||||
|
app.installTranslator(&translator);
|
||||||
|
}
|
||||||
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("UTF8");
|
QTextCodec *codec = QTextCodec::codecForName("UTF8");
|
||||||
if (codec) {
|
if (codec) {
|
||||||
|
18
src/resources/icons/settings.svg
Normal file
18
src/resources/icons/settings.svg
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 16.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
|
||||||
|
<path d="M450,138.3l-47.7,48.5l-2.7,2.8l-1.6,1.7c-1.1,0.8-2.4,1.2-3.9,1.2c-1.6,0-3.1-0.6-4.3-1.6l-0.9-0.9l-2.7-2.7l-41.3-42.1
|
||||||
|
l-2.2-2.2l-1.7-1.7c-1-1.5-1.6-3.4-1.6-5.3c0-1.7,0.6-3.2,1.6-4.4l0.7-0.8l2.6-2.6l47.9-48.7c-5.1-10.1-24.7-14.9-35.1-14.1
|
||||||
|
c-17.1,1.3-34.7,7-52.8,25.5c-0.7,0.8-1.5,1.6-2.2,2.3C277.5,120,272.6,156,282.6,189c0.7,1.4,1.3,3.1,1.6,4.6
|
||||||
|
c1.1,5.5-0.4,10.2-4,13.5l-37.9,36.4c-11.8-12-13.5-13.6-13.5-13.6c-2-2-6-3.3-9.5-1.2l-5.9,3.6c-22.7-23.1-32.3-32.4-35.4-43.6
|
||||||
|
c-3.2-11.7-0.3-27.3,2.7-33.1c2.5-4.6,10.3-8.9,16.9-9.4l8.6,8.8c2,2,5.1,2,7.1,0l30.9-31.4c2-2,2-5.3,0-7.3l-49.9-50.7
|
||||||
|
c-2-2-5.2-2-7.1,0l-30.9,31.4c-2,2-2,5.3,0,7.3l3.3,3.4c0,4.9-0.7,12.5-4.7,16.6c-6.2,6.3-18.5-1-26.5,4.7
|
||||||
|
c-7.9,5.6-17.9,14.6-24.3,21c-6.3,6.4-30.5,31.8-47.8,74.6c-17.3,42.8-4,82.5,5.4,92.9c5,5.5,14.1,11.1,12.5,0.7
|
||||||
|
c-1.6-10.5-4.2-46.9,7.7-61.8c11.9-14.9,27.6-27.1,48-28.1c19.6-1,30.9,5.7,56.3,31.5l-2.8,5.2c-1.8,3.4-0.8,7.7,1.2,9.7
|
||||||
|
c0,0,1.5,1.6,12.1,12.4l-97.2,93.2c-16.2,14.3-15.3,40.5-0.3,56c15.2,15.2,41.1,16.3,55.2-0.2l91.4-98.6
|
||||||
|
c49.1,52.3,93.3,107.4,93.3,107.4c2,2,5.2,2,7.1,0l49.9-50.7c2-2,2-5.2,0-7.3c0,0-55.2-45.7-107-96.2l35.5-38.3
|
||||||
|
c3.3-3.7,7.9-5.2,13.3-4.1c1.5,0.3,3.1,1,4.5,1.7c32.4,10.2,67.8,5.2,94-19.8c0.8-0.7,1.5-1.5,2.3-2.3c18.1-18.4,23.7-36.4,25-53.8
|
||||||
|
C464.7,163.5,460.2,143.8,450,138.3z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
@ -12,6 +12,7 @@ highlight_selected_word=1
|
|||||||
highlight_searched_word=1
|
highlight_searched_word=1
|
||||||
current_background_color=System
|
current_background_color=System
|
||||||
current_render_background_color=System
|
current_render_background_color=System
|
||||||
|
language=System
|
||||||
|
|
||||||
[predefined_colors]
|
[predefined_colors]
|
||||||
1\name=White
|
1\name=White
|
||||||
|
13
src/src.pro
13
src/src.pro
@ -13,8 +13,10 @@ TEMPLATE = app
|
|||||||
|
|
||||||
RC_ICONS = resources/icons/vnote.ico
|
RC_ICONS = resources/icons/vnote.ico
|
||||||
|
|
||||||
|
TRANSLATIONS += translations/vnote_zh_CN.ts
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
vmainwindow.cpp \
|
vmainwindow.cpp \
|
||||||
vdirectorytree.cpp \
|
vdirectorytree.cpp \
|
||||||
vnote.cpp \
|
vnote.cpp \
|
||||||
vnotebook.cpp \
|
vnotebook.cpp \
|
||||||
@ -49,7 +51,8 @@ SOURCES += main.cpp\
|
|||||||
vnofocusitemdelegate.cpp \
|
vnofocusitemdelegate.cpp \
|
||||||
vavatar.cpp \
|
vavatar.cpp \
|
||||||
vmdedit.cpp \
|
vmdedit.cpp \
|
||||||
dialog/vfindreplacedialog.cpp
|
dialog/vfindreplacedialog.cpp \
|
||||||
|
dialog/vsettingsdialog.cpp
|
||||||
|
|
||||||
HEADERS += vmainwindow.h \
|
HEADERS += vmainwindow.h \
|
||||||
vdirectorytree.h \
|
vdirectorytree.h \
|
||||||
@ -87,10 +90,12 @@ HEADERS += vmainwindow.h \
|
|||||||
vnofocusitemdelegate.h \
|
vnofocusitemdelegate.h \
|
||||||
vavatar.h \
|
vavatar.h \
|
||||||
vmdedit.h \
|
vmdedit.h \
|
||||||
dialog/vfindreplacedialog.h
|
dialog/vfindreplacedialog.h \
|
||||||
|
dialog/vsettingsdialog.h
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
vnote.qrc
|
vnote.qrc \
|
||||||
|
translations.qrc
|
||||||
|
|
||||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../hoedown/release/ -lhoedown
|
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../hoedown/release/ -lhoedown
|
||||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../hoedown/debug/ -lhoedown
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../hoedown/debug/ -lhoedown
|
||||||
|
5
src/translations.qrc
Normal file
5
src/translations.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>translations/vnote_zh_CN.qm</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
BIN
src/translations/vnote_zh_CN.qm
Normal file
BIN
src/translations/vnote_zh_CN.qm
Normal file
Binary file not shown.
1054
src/translations/vnote_zh_CN.ts
Normal file
1054
src/translations/vnote_zh_CN.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,10 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
|
const QVector<QPair<QString, QString>> VUtils::c_availableLanguages = {QPair<QString, QString>("en_US", "Englisth (US)"),
|
||||||
|
QPair<QString, QString>("zh_CN", "Chinese")};
|
||||||
|
|
||||||
VUtils::VUtils()
|
VUtils::VUtils()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -302,3 +306,18 @@ QString VUtils::generateCopiedDirName(const QString &p_parentDirPath, const QStr
|
|||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QVector<QPair<QString, QString>>& VUtils::getAvailableLanguages()
|
||||||
|
{
|
||||||
|
return c_availableLanguages;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VUtils::isValidLanguage(const QString &p_lang)
|
||||||
|
{
|
||||||
|
for (auto lang : c_availableLanguages) {
|
||||||
|
if (lang.first == p_lang) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -35,6 +35,12 @@ public:
|
|||||||
static int showMessage(QMessageBox::Icon p_icon, const QString &p_title, const QString &p_text,
|
static int showMessage(QMessageBox::Icon p_icon, const QString &p_title, const QString &p_text,
|
||||||
const QString &p_infoText, QMessageBox::StandardButtons p_buttons,
|
const QString &p_infoText, QMessageBox::StandardButtons p_buttons,
|
||||||
QMessageBox::StandardButton p_defaultBtn, QWidget *p_parent);
|
QMessageBox::StandardButton p_defaultBtn, QWidget *p_parent);
|
||||||
|
static const QVector<QPair<QString, QString> > &getAvailableLanguages();
|
||||||
|
static bool isValidLanguage(const QString &p_lang);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// <value, name>
|
||||||
|
static const QVector<QPair<QString, QString>> c_availableLanguages;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QString VUtils::directoryNameFromPath(const QString &path)
|
inline QString VUtils::directoryNameFromPath(const QString &path)
|
||||||
|
@ -79,6 +79,8 @@ void VConfigManager::initialize()
|
|||||||
"find_regular_expression").toBool();
|
"find_regular_expression").toBool();
|
||||||
m_findIncrementalSearch = getConfigFromSettings("global",
|
m_findIncrementalSearch = getConfigFromSettings("global",
|
||||||
"find_incremental_search").toBool();
|
"find_incremental_search").toBool();
|
||||||
|
|
||||||
|
m_language = getConfigFromSettings("global", "language").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::readPredefinedColorsFromSettings()
|
void VConfigManager::readPredefinedColorsFromSettings()
|
||||||
|
@ -117,6 +117,9 @@ public:
|
|||||||
inline bool getFindIncrementalSearch() const;
|
inline bool getFindIncrementalSearch() const;
|
||||||
inline void setFindIncrementalSearch(bool p_enabled);
|
inline void setFindIncrementalSearch(bool p_enabled);
|
||||||
|
|
||||||
|
inline QString getLanguage() const;
|
||||||
|
inline void setLanguage(const QString &p_language);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateMarkdownEditStyle();
|
void updateMarkdownEditStyle();
|
||||||
QVariant getConfigFromSettings(const QString §ion, const QString &key);
|
QVariant getConfigFromSettings(const QString §ion, const QString &key);
|
||||||
@ -174,6 +177,9 @@ private:
|
|||||||
bool m_findRegularExpression;
|
bool m_findRegularExpression;
|
||||||
bool m_findIncrementalSearch;
|
bool m_findIncrementalSearch;
|
||||||
|
|
||||||
|
// Language
|
||||||
|
QString m_language;
|
||||||
|
|
||||||
// The name of the config file in each directory
|
// The name of the config file in each directory
|
||||||
static const QString dirConfigFileName;
|
static const QString dirConfigFileName;
|
||||||
// The name of the default configuration file
|
// The name of the default configuration file
|
||||||
@ -491,4 +497,19 @@ inline void VConfigManager::setFindIncrementalSearch(bool p_enabled)
|
|||||||
m_findIncrementalSearch);
|
m_findIncrementalSearch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QString VConfigManager::getLanguage() const
|
||||||
|
{
|
||||||
|
return m_language;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VConfigManager::setLanguage(const QString &p_language)
|
||||||
|
{
|
||||||
|
if (m_language == p_language) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_language = p_language;
|
||||||
|
setConfigToSettings("global", "language",
|
||||||
|
m_language);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VCONFIGMANAGER_H
|
#endif // VCONFIGMANAGER_H
|
||||||
|
@ -523,7 +523,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
|
|||||||
} else {
|
} else {
|
||||||
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
QString("Failed to copy image %1.").arg(images[i]),
|
QString("Failed to copy image %1.").arg(images[i]),
|
||||||
tr("Please check if there already exists a file with the same name and manually copy it"),
|
tr("Please check if there already exists a file with the same name and manually copy it."),
|
||||||
QMessageBox::Ok, QMessageBox::Ok, NULL);
|
QMessageBox::Ok, QMessageBox::Ok, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "vnotebookselector.h"
|
#include "vnotebookselector.h"
|
||||||
#include "vavatar.h"
|
#include "vavatar.h"
|
||||||
#include "dialog/vfindreplacedialog.h"
|
#include "dialog/vfindreplacedialog.h"
|
||||||
|
#include "dialog/vsettingsdialog.h"
|
||||||
|
|
||||||
extern VConfigManager vconfig;
|
extern VConfigManager vconfig;
|
||||||
|
|
||||||
@ -20,7 +21,6 @@ VMainWindow::VMainWindow(QWidget *parent)
|
|||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
|
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
|
||||||
// Must be called before those who uses VConfigManager
|
|
||||||
vnote = new VNote(this);
|
vnote = new VNote(this);
|
||||||
g_vnote = vnote;
|
g_vnote = vnote;
|
||||||
vnote->initPalette(palette());
|
vnote->initPalette(palette());
|
||||||
@ -174,7 +174,7 @@ void VMainWindow::initFileToolBar()
|
|||||||
fileToolBar->setMovable(false);
|
fileToolBar->setMovable(false);
|
||||||
|
|
||||||
newRootDirAct = new QAction(QIcon(":/resources/icons/create_rootdir_tb.svg"),
|
newRootDirAct = new QAction(QIcon(":/resources/icons/create_rootdir_tb.svg"),
|
||||||
tr("New &Rood Directory"), this);
|
tr("New &Root Directory"), this);
|
||||||
newRootDirAct->setStatusTip(tr("Create a root directory in current notebook"));
|
newRootDirAct->setStatusTip(tr("Create a root directory in current notebook"));
|
||||||
connect(newRootDirAct, &QAction::triggered,
|
connect(newRootDirAct, &QAction::triggered,
|
||||||
directoryTree, &VDirectoryTree::newRootDirectory);
|
directoryTree, &VDirectoryTree::newRootDirectory);
|
||||||
@ -321,7 +321,16 @@ void VMainWindow::initFileMenu()
|
|||||||
connect(importNoteAct, &QAction::triggered,
|
connect(importNoteAct, &QAction::triggered,
|
||||||
this, &VMainWindow::importNoteFromFile);
|
this, &VMainWindow::importNoteFromFile);
|
||||||
|
|
||||||
|
// Settings.
|
||||||
|
QAction *settingsAct = new QAction(QIcon(":/resources/icons/settings.svg"),
|
||||||
|
tr("Settings"), this);
|
||||||
|
settingsAct->setStatusTip(tr("View and change settings for VNote"));
|
||||||
|
connect(settingsAct, &QAction::triggered,
|
||||||
|
this, &VMainWindow::viewSettings);
|
||||||
|
|
||||||
fileMenu->addAction(importNoteAct);
|
fileMenu->addAction(importNoteAct);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
fileMenu->addAction(settingsAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::initEditMenu()
|
void VMainWindow::initEditMenu()
|
||||||
@ -379,7 +388,7 @@ void VMainWindow::initEditMenu()
|
|||||||
|
|
||||||
// Expand Tab into spaces.
|
// Expand Tab into spaces.
|
||||||
QAction *expandTabAct = new QAction(tr("&Expand Tab"), this);
|
QAction *expandTabAct = new QAction(tr("&Expand Tab"), this);
|
||||||
expandTabAct->setStatusTip(tr("Expand entered tab to spaces"));
|
expandTabAct->setStatusTip(tr("Expand entered Tab to spaces"));
|
||||||
expandTabAct->setCheckable(true);
|
expandTabAct->setCheckable(true);
|
||||||
connect(expandTabAct, &QAction::triggered,
|
connect(expandTabAct, &QAction::triggered,
|
||||||
this, &VMainWindow::changeExpandTab);
|
this, &VMainWindow::changeExpandTab);
|
||||||
@ -387,15 +396,15 @@ void VMainWindow::initEditMenu()
|
|||||||
// Tab stop width.
|
// Tab stop width.
|
||||||
QActionGroup *tabStopWidthAct = new QActionGroup(this);
|
QActionGroup *tabStopWidthAct = new QActionGroup(this);
|
||||||
QAction *twoSpaceTabAct = new QAction(tr("2 Spaces"), tabStopWidthAct);
|
QAction *twoSpaceTabAct = new QAction(tr("2 Spaces"), tabStopWidthAct);
|
||||||
twoSpaceTabAct->setStatusTip(tr("Expand tab to 2 spaces"));
|
twoSpaceTabAct->setStatusTip(tr("Expand Tab to 2 spaces"));
|
||||||
twoSpaceTabAct->setCheckable(true);
|
twoSpaceTabAct->setCheckable(true);
|
||||||
twoSpaceTabAct->setData(2);
|
twoSpaceTabAct->setData(2);
|
||||||
QAction *fourSpaceTabAct = new QAction(tr("4 Spaces"), tabStopWidthAct);
|
QAction *fourSpaceTabAct = new QAction(tr("4 Spaces"), tabStopWidthAct);
|
||||||
fourSpaceTabAct->setStatusTip(tr("Expand tab to 4 spaces"));
|
fourSpaceTabAct->setStatusTip(tr("Expand Tab to 4 spaces"));
|
||||||
fourSpaceTabAct->setCheckable(true);
|
fourSpaceTabAct->setCheckable(true);
|
||||||
fourSpaceTabAct->setData(4);
|
fourSpaceTabAct->setData(4);
|
||||||
QAction *eightSpaceTabAct = new QAction(tr("8 Spaces"), tabStopWidthAct);
|
QAction *eightSpaceTabAct = new QAction(tr("8 Spaces"), tabStopWidthAct);
|
||||||
eightSpaceTabAct->setStatusTip(tr("Expand tab to 8 spaces"));
|
eightSpaceTabAct->setStatusTip(tr("Expand Tab to 8 spaces"));
|
||||||
eightSpaceTabAct->setCheckable(true);
|
eightSpaceTabAct->setCheckable(true);
|
||||||
eightSpaceTabAct->setData(8);
|
eightSpaceTabAct->setData(8);
|
||||||
connect(tabStopWidthAct, &QActionGroup::triggered,
|
connect(tabStopWidthAct, &QActionGroup::triggered,
|
||||||
@ -530,12 +539,12 @@ void VMainWindow::importNoteFromFile()
|
|||||||
failedFiles.append(files[i]);
|
failedFiles.append(files[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QMessageBox msgBox(QMessageBox::Information, tr("Import note from file"),
|
QMessageBox msgBox(QMessageBox::Information, tr("Import Notes From File"),
|
||||||
QString("Imported notes: %1 succeed, %2 failed.")
|
QString("Imported notes: %1 succeed, %2 failed.")
|
||||||
.arg(files.size() - failedFiles.size()).arg(failedFiles.size()),
|
.arg(files.size() - failedFiles.size()).arg(failedFiles.size()),
|
||||||
QMessageBox::Ok, this);
|
QMessageBox::Ok, this);
|
||||||
if (!failedFiles.isEmpty()) {
|
if (!failedFiles.isEmpty()) {
|
||||||
msgBox.setInformativeText(tr("Failed to import files may be due to name conflicts."));
|
msgBox.setInformativeText(tr("Failed to import files maybe due to name conflicts."));
|
||||||
}
|
}
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
@ -617,7 +626,7 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
|
|||||||
QMenu *renderBgMenu = menu->addMenu(tr("&Rendering Background"));
|
QMenu *renderBgMenu = menu->addMenu(tr("&Rendering Background"));
|
||||||
const QString &curBgColor = vconfig.getCurRenderBackgroundColor();
|
const QString &curBgColor = vconfig.getCurRenderBackgroundColor();
|
||||||
QAction *tmpAct = new QAction(tr("System"), renderBackgroundAct);
|
QAction *tmpAct = new QAction(tr("System"), renderBackgroundAct);
|
||||||
tmpAct->setStatusTip(tr("Use system's background color configuration for markdown rendering"));
|
tmpAct->setStatusTip(tr("Use system's background color configuration for Markdown rendering"));
|
||||||
tmpAct->setCheckable(true);
|
tmpAct->setCheckable(true);
|
||||||
tmpAct->setData("System");
|
tmpAct->setData("System");
|
||||||
if (curBgColor == "System") {
|
if (curBgColor == "System") {
|
||||||
@ -628,7 +637,7 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
|
|||||||
const QVector<VColor> &bgColors = vconfig.getPredefinedColors();
|
const QVector<VColor> &bgColors = vconfig.getPredefinedColors();
|
||||||
for (int i = 0; i < bgColors.size(); ++i) {
|
for (int i = 0; i < bgColors.size(); ++i) {
|
||||||
tmpAct = new QAction(bgColors[i].name, renderBackgroundAct);
|
tmpAct = new QAction(bgColors[i].name, renderBackgroundAct);
|
||||||
tmpAct->setStatusTip(tr("Set as the background color for markdown rendering"));
|
tmpAct->setStatusTip(tr("Set as the background color for Markdown rendering"));
|
||||||
tmpAct->setCheckable(true);
|
tmpAct->setCheckable(true);
|
||||||
tmpAct->setData(bgColors[i].name);
|
tmpAct->setData(bgColors[i].name);
|
||||||
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
||||||
@ -943,3 +952,8 @@ void VMainWindow::openFindDialog()
|
|||||||
m_findReplaceDialog->openDialog(editArea->getSelectedText());
|
m_findReplaceDialog->openDialog(editArea->getSelectedText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::viewSettings()
|
||||||
|
{
|
||||||
|
VSettingsDialog settingsDialog(this);
|
||||||
|
settingsDialog.exec();
|
||||||
|
}
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void importNoteFromFile();
|
void importNoteFromFile();
|
||||||
|
void viewSettings();
|
||||||
void changeMarkdownConverter(QAction *action);
|
void changeMarkdownConverter(QAction *action);
|
||||||
void aboutMessage();
|
void aboutMessage();
|
||||||
void changeExpandTab(bool checked);
|
void changeExpandTab(bool checked);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "vconfigmanager.h"
|
#include "vconfigmanager.h"
|
||||||
#include "vmainwindow.h"
|
#include "vmainwindow.h"
|
||||||
|
|
||||||
VConfigManager vconfig;
|
extern VConfigManager vconfig;
|
||||||
|
|
||||||
QString VNote::templateHtml;
|
QString VNote::templateHtml;
|
||||||
QString VNote::preTemplateHtml;
|
QString VNote::preTemplateHtml;
|
||||||
@ -17,7 +17,6 @@ QString VNote::postTemplateHtml;
|
|||||||
VNote::VNote(QObject *parent)
|
VNote::VNote(QObject *parent)
|
||||||
: QObject(parent), m_mainWindow(dynamic_cast<VMainWindow *>(parent))
|
: QObject(parent), m_mainWindow(dynamic_cast<VMainWindow *>(parent))
|
||||||
{
|
{
|
||||||
vconfig.initialize();
|
|
||||||
initTemplate();
|
initTemplate();
|
||||||
vconfig.getNotebooks(m_notebooks, this);
|
vconfig.getNotebooks(m_notebooks, this);
|
||||||
}
|
}
|
||||||
|
@ -84,5 +84,6 @@
|
|||||||
<file>resources/icons/close.svg</file>
|
<file>resources/icons/close.svg</file>
|
||||||
<file>resources/icons/find_replace.svg</file>
|
<file>resources/icons/find_replace.svg</file>
|
||||||
<file>resources/icons/search_wrap.svg</file>
|
<file>resources/icons/search_wrap.svg</file>
|
||||||
|
<file>resources/icons/settings.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user