OSDN Git Service

[UI][Qt] Add font selection to debugger and log view dialogs.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 18 Aug 2019 17:49:49 +0000 (02:49 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 18 Aug 2019 17:49:49 +0000 (02:49 +0900)
[Qt][CONFIG] Keep font metrics and window size of debugger and log viewer.Save to foo.ini file.

source/src/config.cpp
source/src/config.h
source/src/qt/emuutils/CMakeLists.txt
source/src/qt/gui/CMakeLists.txt
source/src/qt/gui/display_log.cpp
source/src/qt/gui/display_log.h
source/src/qt/gui/qt_debugger_tmpl.cpp
source/src/qt/gui/qt_debugger_tmpl.h

index 9422d9e..f1b3c83 100644 (file)
@@ -217,6 +217,9 @@ void initialize_config()
                }
                // Extra UI
                config.cursor_as_ten_key = CONFIG_CURSOR_AS_CURSOR;
+               memset(config.debugwindow_font, 0x00, sizeof(config.debugwindow_font));
+               memset(config.logwindow_font, 0x00, sizeof(config.logwindow_font));
+               
        #if defined(_FM7) || defined(_FMNEW7) || defined(_FM8) \
            || defined(_FM77_VARIANTS) || defined(_FM77AV_VARIANTS)             
                config.numpad_enter_as_fullkey = false;
@@ -488,6 +491,12 @@ void load_config(const _TCHAR *config_path)
                config.cursor_as_ten_key = MyGetPrivateProfileInt(_T("Qt"), _T("CursorAsTenKey"), config.cursor_as_ten_key, config_path);
                config.numpad_enter_as_fullkey = MyGetPrivateProfileBool(_T("Qt"), _T("NumpadEnterAsFullKey"), config.numpad_enter_as_fullkey, config_path);
                config.host_keyboard_type = MyGetPrivateProfileInt(_T("Qt"), _T("HostKeyboardType"), config.host_keyboard_type, config_path);
+               MyGetPrivateProfileString(_T("Qt"), _T("DebugWindowFont"), _T("Sans"), config.debugwindow_font, sizeof(config.debugwindow_font) - 1, config_path);
+               config.debugwindow_width = MyGetPrivateProfileInt(_T("Qt"), _T("DebugWindowWidth"), 800, config_path);
+               config.debugwindow_height = MyGetPrivateProfileInt(_T("Qt"), _T("DebugWindowHeight"), 500, config_path);
+               MyGetPrivateProfileString(_T("Qt"), _T("LogWindowFont"), _T("Sans"), config.logwindow_font, sizeof(config.logwindow_font) - 1, config_path);
+               config.logwindow_width = MyGetPrivateProfileInt(_T("Qt"), _T("LogWindowWidth"), 800, config_path);
+               config.logwindow_height = MyGetPrivateProfileInt(_T("Qt"), _T("LogWindowHeight"), 500, config_path);
 
                
                // Movie load/save.
@@ -833,6 +842,12 @@ void save_config(const _TCHAR *config_path)
                MyWritePrivateProfileInt(_T("Qt"), _T("CursorAsTenKey"), config.cursor_as_ten_key, config_path);
                MyWritePrivateProfileBool(_T("Qt"), _T("NumpadEnterAsFullKey"), config.numpad_enter_as_fullkey, config_path);
                MyWritePrivateProfileInt(_T("Qt"), _T("HostKeyboardType"), config.host_keyboard_type, config_path);
+               MyWritePrivateProfileString(_T("Qt"), _T("DebugWindowFont"), config.debugwindow_font, config_path);
+               MyWritePrivateProfileInt(_T("Qt"), _T("DebugWindowWidth"), config.debugwindow_width, config_path);
+               MyWritePrivateProfileInt(_T("Qt"), _T("DebugWindowHeight"), config.debugwindow_height, config_path);
+               MyWritePrivateProfileString(_T("Qt"), _T("LogWindowFont"), config.logwindow_font, config_path);
+               MyWritePrivateProfileInt(_T("Qt"), _T("LogWindowWidth"), config.logwindow_width, config_path);
+               MyWritePrivateProfileInt(_T("Qt"), _T("LogWindowHeight"), config.logwindow_height, config_path);
 
                for(i = 0; i < 16; i++) {
                        _TCHAR name[256];
index 27a4ec7..8ef5444 100644 (file)
@@ -244,6 +244,13 @@ typedef struct {
        int render_major_version;
        int render_minor_version;
        bool disk_count_immediate[16]; // Hack for MB8877, FLEX for FM-7.
+       _TCHAR debugwindow_font[1024];
+       _TCHAR logwindow_font[1024];
+       int debugwindow_width;
+       int debugwindow_height;
+       int logwindow_width;
+       int logwindow_height;
+       
 #endif 
        
        // sound
index 1151ad6..3f3c41b 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/emuutils")
 
-SET(THIS_LIB_VERSION 2.16.2)
+SET(THIS_LIB_VERSION 2.16.3)
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
index a3c9eda..548b4b0 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 2.19.4)
+set(THIS_LIB_VERSION 2.19.5)
 #include(cotire)
 #include(PrecompiledHeader)
 
index 3bf8e0e..f2f90de 100644 (file)
@@ -8,6 +8,7 @@
 #include <QIODevice>
 #include <QUrl>
 #include <QStringList>
+#include <QApplication>
 
 #include <QTextBrowser>
 #include <QLabel>
 #include <QVBoxLayout>
 #include <QFont>
 #include <QGridLayout>
+#include <QFontDialog>
+#include <QPushButton>
 #include <QTimer>
 #include <QMutexLocker>
+#include <QResizeEvent>
+#include <QSize>
 
 #include "mainwidget_base.h"
 #include "display_log.h"
@@ -81,6 +86,34 @@ void Dlg_LogViewerBind::do_update(void)
        emit sig_throw_desc(str, bind_int);
 }
 
+void Dlg_LogViewer::set_font(const QFont &font)
+{
+       TextBox->setFont(font);
+       if(!(font.toString().isEmpty())) {
+               memset(config.logwindow_font, 0x00, sizeof(config.logwindow_font));
+               snprintf(config.logwindow_font, sizeof(config.logwindow_font) - 1, "%s", font.toString().toLocal8Bit().constData());
+       }
+}
+
+void Dlg_LogViewer::rise_font_dialog(void)
+{
+       QFontDialog *dlg = new QFontDialog(TextBox->font(), this);
+       connect(dlg, SIGNAL(fontSelected(const QFont)), this, SLOT(set_font(const QFont)));
+       dlg->show();
+}
+
+void Dlg_LogViewer::resizeEvent(QResizeEvent *event)
+{
+       QSize s = event->size();
+       int width = s.width();
+       int height = s.height();
+       if(width < 320) width = 320;
+       if(height < 200) height = 200;
+       config.logwindow_height = height;
+       config.logwindow_width = width;
+}
+
+
 Dlg_LogViewer::Dlg_LogViewer(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent, QString _domain, uint32_t level) : QWidget(parent)
 {
        lock_mutex = new QMutex(QMutex::Recursive);
@@ -91,7 +124,7 @@ Dlg_LogViewer::Dlg_LogViewer(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent
        using_flags = p;
        csp_logger = logger;
        TextBox = new QTextBrowser();
-       TextBox->setStyleSheet("font: 12pt \"Sans\";");
+//     TextBox->setStyleSheet("font: 12pt \"Sans\";");
        TextBox->setMinimumSize(800, 470);
        TextBox->setOpenExternalLinks(true);
        if(csp_logger != NULL) {
@@ -128,7 +161,15 @@ Dlg_LogViewer::Dlg_LogViewer(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent
        connect(this, SIGNAL(sig_text_update(QString)), TextBox, SLOT(setText(QString)));
        connect(this, SIGNAL(sig_text_append(QString)), TextBox, SLOT(append(QString)));
        MasterLayout = new QGridLayout;
-       MasterLayout->addWidget(TextBox, 0, 0, 4, 4);
+       FontDlgButton = new QPushButton(QApplication::translate("LogWindow", "Set Font", 0),this);
+       if(strlen(config.logwindow_font) > 0) {
+               QFont font;
+               font.fromString(QString::fromLocal8Bit(config.logwindow_font));
+               TextBox->setFont(font);
+       }
+       connect(FontDlgButton, SIGNAL(pressed()), this, SLOT(rise_font_dialog()));
+       MasterLayout->addWidget(FontDlgButton, 0, 3, Qt::AlignRight);
+       MasterLayout->addWidget(TextBox, 1, 0, 4, 4);
 
        UpdateTimer = new QTimer(this);
        UpdateTimer->setInterval(500); // 500ms
@@ -136,6 +177,12 @@ Dlg_LogViewer::Dlg_LogViewer(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent
        connect(UpdateTimer, SIGNAL(timeout()), this, SLOT(do_update()));
        UpdateTimer->start();
        this->setLayout(MasterLayout);
+
+       int w = config.logwindow_width;
+       int h = config.logwindow_height;
+       if(w < 320) w = 320;
+       if(h < 200) h = 200;
+       this->resize(w, h);
 }
 
 Dlg_LogViewer::~Dlg_LogViewer()
index 790da79..33bd9e3 100644 (file)
@@ -10,6 +10,7 @@
 #include <QUrl>
 #include <QStringList>
 #include <QWidget>
+#include <QFont>
 
 #include "common.h"
 
@@ -21,6 +22,9 @@ class QFont;
 class QVBoxLayout;
 class QGridLayout;
 class QGroupBox;
+class QFontDialog;
+class QPushButton;
+class QResizeEvent;
 class QTimer;
 class QMutex;
 class USING_FLAGS;
@@ -62,16 +66,22 @@ protected:
        QTextBrowser *TextBox;
        QGridLayout *MasterLayout;
        QTimer *UpdateTimer;
+       QPushButton *FontDlgButton;
+
        USING_FLAGS *using_flags;
        QMutex *lock_mutex;
 public:
        Dlg_LogViewer(USING_FLAGS *p, CSP_Logger * logger, QWidget *parent, QString _domain = QString::fromUtf8(""), uint32_t _level = 0xffffffff);
        ~Dlg_LogViewer();
+       virtual void resizeEvent(QResizeEvent *event);
 
 public slots:
        void do_search_by_domain(QString _domain_name, uint32_t _level);
        void do_update(void);
        void do_refresh(void);
+       void set_font(const QFont &font);
+       void rise_font_dialog(void);
+
 signals:
        int sig_text_clear();
        int sig_text_update(QString);
index 13cb77b..63c35bf 100644 (file)
 #include <fcntl.h>
 #include <QObject>
 #include <QMetaObject>
+#include <QPlainTextEdit>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QFontDialog>
+#include <QFont>
+#include <QApplication>
+#include <QResizeEvent>
+#include <QSize>
 
 #include "qt_debugger_tmpl.h"
 #include "qt_lineeditplus.h"
 #include "osd_base.h"
+#include "../../config.h"
 
 void CSP_Debugger_Tmpl::set_string_attr(QString color, bool is_strong)
 {
@@ -114,6 +124,34 @@ void CSP_Debugger_Tmpl::run(void)
        connect(parent_object, SIGNAL(quit_debugger_thread()), this, SLOT(close()));
 }
 
+void CSP_Debugger_Tmpl::set_font(const QFont &font)
+{
+       text_command->setFont(font);
+       text->setFont(font);
+       if(!(font.toString().isEmpty())) {
+               memset(config.debugwindow_font, 0x00, sizeof(config.debugwindow_font));
+               snprintf(config.debugwindow_font, sizeof(config.debugwindow_font) - 1, "%s", font.toString().toLocal8Bit().constData());
+       }
+}
+
+void CSP_Debugger_Tmpl::rise_font_dialog(void)
+{
+       QFontDialog *dlg = new QFontDialog(text->font(), this);
+       connect(dlg, SIGNAL(fontSelected(const QFont)), this, SLOT(set_font(const QFont)));
+       dlg->show();
+}
+
+
+void CSP_Debugger_Tmpl::resizeEvent(QResizeEvent *event)
+{
+       QSize s = event->size();
+       int width = s.width();
+       int height = s.height();
+       if(width < 320) width = 320;
+       if(height < 200) height = 200;
+       config.debugwindow_height = height;
+       config.debugwindow_width = width;
+}
 
 CSP_Debugger_Tmpl::CSP_Debugger_Tmpl(OSD_BASE* p_osd, QWidget *parent) : QWidget(parent, Qt::Window)
 {
@@ -131,20 +169,38 @@ CSP_Debugger_Tmpl::CSP_Debugger_Tmpl(OSD_BASE* p_osd, QWidget *parent) : QWidget
        text_command->setReadOnly(false);
        text_command->setEnabled(true);
        text_command->clear();
-
+       call_font_dialog = new QPushButton(QApplication::translate("Debugger", "Set Font", 0),this);
+       if(strlen(config.debugwindow_font) > 0) {
+               QFont font;
+               font.fromString(QString::fromLocal8Bit(config.debugwindow_font));
+               text->setFont(font);
+               text_command->setFont(font);
+       }
        complete_list.clear();
 
        connect(this, SIGNAL(sig_apply_complete_list(QStringList)), text_command, SLOT(setCompleteList(QStringList)));
+       connect(call_font_dialog, SIGNAL(pressed()), this, SLOT(rise_font_dialog()));
        connect(p_osd, SIGNAL(sig_apply_dbg_completion_list()), this, SLOT(apply_complete_list()));
        connect(p_osd, SIGNAL(sig_clear_dbg_completion_list()), this, SLOT(clear_complete_list()));
        connect(p_osd, SIGNAL(sig_add_dbg_completion_list(_TCHAR *)), this, SLOT(add_complete_list(_TCHAR *)));
-       
-       VBoxWindow = new QVBoxLayout;
 
+       VBoxWindow = new QVBoxLayout;
+       TailButtons = new QHBoxLayout;
+       
+       TailButtons->setAlignment(Qt::AlignRight);
+       TailButtons->addStretch();
+       TailButtons->addWidget(call_font_dialog);
+       VBoxWindow->addLayout(TailButtons);
        VBoxWindow->addWidget(text);
        VBoxWindow->addWidget(text_command);
+       
+       int w = config.debugwindow_width;
+       int h = config.debugwindow_height;
+       if(w < 320) w = 320;
+       if(h < 200) h = 200;
+       
        this->setLayout(VBoxWindow);
-       this->resize(640, 500);
+       this->resize(w, h);
 }
 
 
index ce4cb4f..3fd6e0a 100644 (file)
 #include <QMetaObject>
 #include <QThread>
 #include <QWidget>
-#include <QPlainTextEdit>
 
 #include <QString>
 #include <QStringList>
-#include <QVBoxLayout>
-#include <QTimer>
-#include <QCloseEvent>
 
 #include <list>
 #include <string>
 
 QT_BEGIN_NAMESPACE     
 
+class QTextEdit;
+class QVBoxLayout;
+class QHBoxLayout;
+class QPushButton;
+class QFontDialog;
+class QResizeEvent;
+
 class CSP_DebuggerThread;
 class QLineEditPlus;
 class OSD_BASE;
@@ -42,7 +45,10 @@ class DLL_PREFIX CSP_Debugger_Tmpl : public QWidget
        QWidget *widget;
        QTextEdit *text;
        QLineEditPlus *text_command;
+       QPushButton *call_font_dialog;
+       QFontDialog *font_dialog;
        QVBoxLayout *VBoxWindow;
+       QHBoxLayout *TailButtons;
 
        bool string_is_strong;
        QString text_color;
@@ -52,6 +58,7 @@ class DLL_PREFIX CSP_Debugger_Tmpl : public QWidget
        ~CSP_Debugger_Tmpl();
        //virtual void closeEvent(QCloseEvent *event);
        QStringList &get_complete_list();
+       virtual void resizeEvent(QResizeEvent *event);
 public slots:
        void stop_polling();
        void put_string(QString);
@@ -65,7 +72,8 @@ public slots:
        
        void clear_complete_list();
        void apply_complete_list();
-       
+       void set_font(const QFont &font);
+       void rise_font_dialog();
 signals:
        void sig_put_string(QString);
        void sig_run_command(QString);