improve performance of console, shader view

This commit is contained in:
Garux 2023-05-18 19:09:19 +06:00
parent 8c92cb69ed
commit 2b3a34b299
3 changed files with 30 additions and 30 deletions

View File

@ -35,7 +35,7 @@
#include "gtkmisc.h" #include "gtkmisc.h"
#include "mainframe.h" #include "mainframe.h"
#include <QTextEdit> #include <QPlainTextEdit>
#include <QContextMenuEvent> #include <QContextMenuEvent>
// handle to the console log file // handle to the console log file
@ -81,15 +81,15 @@ void Sys_LogFile( bool enable ){
} }
} }
QTextEdit* g_console = 0; QPlainTextEdit* g_console = 0;
class QTextEdit_console : public QTextEdit class QPlainTextEdit_console : public QPlainTextEdit
{ {
protected: protected:
void contextMenuEvent( QContextMenuEvent *event ) override { void contextMenuEvent( QContextMenuEvent *event ) override {
QMenu *menu = createStandardContextMenu(); QMenu *menu = createStandardContextMenu();
QAction *action = menu->addAction( "Clear" ); QAction *action = menu->addAction( "Clear" );
connect( action, &QAction::triggered, this, &QTextEdit::clear ); connect( action, &QAction::triggered, this, &QPlainTextEdit::clear );
menu->exec( event->globalPos() ); menu->exec( event->globalPos() );
delete menu; delete menu;
} }
@ -97,10 +97,9 @@ protected:
QWidget* Console_constructWindow(){ QWidget* Console_constructWindow(){
QTextEdit *text = new QTextEdit_console(); QPlainTextEdit *text = new QPlainTextEdit_console();
text->setReadOnly( true ); text->setReadOnly( true );
text->setUndoRedoEnabled( false ); text->setUndoRedoEnabled( false );
text->setAcceptRichText( false );
text->setMinimumHeight( 10 ); text->setMinimumHeight( 10 );
text->setFocusPolicy( Qt::FocusPolicy::NoFocus ); text->setFocusPolicy( Qt::FocusPolicy::NoFocus );
@ -120,9 +119,9 @@ QWidget* Console_constructWindow(){
class GtkTextBufferOutputStream : public TextOutputStream class GtkTextBufferOutputStream : public TextOutputStream
{ {
QTextEdit* textBuffer; QPlainTextEdit* textBuffer;
public: public:
GtkTextBufferOutputStream( QTextEdit* textBuffer ) : textBuffer( textBuffer ) { GtkTextBufferOutputStream( QPlainTextEdit* textBuffer ) : textBuffer( textBuffer ) {
} }
std::size_t std::size_t
#ifdef __GNUC__ #ifdef __GNUC__
@ -152,22 +151,26 @@ std::size_t Sys_Print( int level, const char* buf, std::size_t length ){
if ( level != SYS_NOCON ) { if ( level != SYS_NOCON ) {
if ( g_console != 0 ) { if ( g_console != 0 ) {
g_console->moveCursor( QTextCursor::End ); // must go before setTextColor() g_console->moveCursor( QTextCursor::End ); // must go before setTextColor() & insertPlainText()
{
QTextCharFormat format = g_console->currentCharFormat();
switch ( level ) switch ( level )
{ {
case SYS_WRN: case SYS_WRN:
g_console->setTextColor( QColor( 255, 127, 0 ) ); format.setForeground( QColor( 255, 127, 0 ) );
break; break;
case SYS_ERR: case SYS_ERR:
g_console->setTextColor( QColor( 255, 0, 0 ) ); format.setForeground( QColor( 255, 0, 0 ) );
break; break;
case SYS_STD: case SYS_STD:
case SYS_VRB: case SYS_VRB:
default: default:
g_console->setTextColor( g_console->palette().text().color() ); format.setForeground( g_console->palette().text().color() );
break; break;
} }
g_console->setCurrentCharFormat( format );
}
{ {
GtkTextBufferOutputStream textBuffer( g_console ); GtkTextBufferOutputStream textBuffer( g_console );

View File

@ -38,7 +38,7 @@
#include <QSplitter> #include <QSplitter>
#include <QTreeWidget> #include <QTreeWidget>
#include <QHeaderView> #include <QHeaderView>
#include <QTextEdit> #include <QPlainTextEdit>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QGridLayout> #include <QGridLayout>
@ -691,7 +691,7 @@ namespace
bool g_entityInspector_windowConstructed = false; bool g_entityInspector_windowConstructed = false;
QTreeWidget* g_entityClassList; QTreeWidget* g_entityClassList;
QTextEdit* g_entityClassComment; QPlainTextEdit* g_entityClassComment;
QCheckBox* g_entitySpawnflagsCheck[MAX_FLAGS]; QCheckBox* g_entitySpawnflagsCheck[MAX_FLAGS];
@ -1192,10 +1192,9 @@ QWidget* EntityInspector_constructWindow( QWidget* toplevel ){
splitter->addWidget( tree ); splitter->addWidget( tree );
} }
{ {
auto text = g_entityClassComment = new QTextEdit; auto text = g_entityClassComment = new QPlainTextEdit;
text->setReadOnly( true ); text->setReadOnly( true );
text->setUndoRedoEnabled( false ); text->setUndoRedoEnabled( false );
text->setAcceptRichText( false );
splitter->addWidget( text ); splitter->addWidget( text );
} }

View File

@ -56,7 +56,6 @@
#include "gtkutil/guisettings.h" #include "gtkutil/guisettings.h"
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QComboBox> #include <QComboBox>
#include <QTextEdit>
#include "os/path.h" #include "os/path.h"
#include "math/aabb.h" #include "math/aabb.h"
@ -405,7 +404,7 @@ void DoAbout(){
class TextEditor class TextEditor
{ {
QWidget *m_window = 0; QWidget *m_window = 0;
QTextEdit *m_textView; // slave, text widget from the gtk editor QPlainTextEdit *m_textView; // slave, text widget from the gtk editor
QPushButton *m_button; // save button QPushButton *m_button; // save button
CopiedString m_filename; CopiedString m_filename;
@ -416,9 +415,8 @@ class TextEditor
auto *vbox = new QVBoxLayout( m_window ); auto *vbox = new QVBoxLayout( m_window );
vbox->setContentsMargins( 0, 0, 0, 0 ); vbox->setContentsMargins( 0, 0, 0, 0 );
m_textView = new QTextEdit; m_textView = new QPlainTextEdit;
m_textView->setAcceptRichText( false ); m_textView->setLineWrapMode( QPlainTextEdit::LineWrapMode::NoWrap );
m_textView->setLineWrapMode( QTextEdit::LineWrapMode::NoWrap );
vbox->addWidget( m_textView ); vbox->addWidget( m_textView );
m_button = new QPushButton( "Save" ); m_button = new QPushButton( "Save" );