From 6b5fa194b7f8ea1805de7850377964c4b98e4d68 Mon Sep 17 00:00:00 2001 From: live Date: Tue, 17 Mar 2020 10:51:11 +0100 Subject: [PATCH] Improved occurences highlighting --- src/TextureData.cpp | 11 ++++---- src/editors/SourceEditor.cpp | 14 ++++------ src/editors/SourceEditor.h | 2 +- src/editors/TextureItem.cpp | 54 +++++++++++++++--------------------- src/editors/TextureItem.h | 1 + 5 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/TextureData.cpp b/src/TextureData.cpp index 43b8a230..ec20b7b0 100644 --- a/src/TextureData.cpp +++ b/src/TextureData.cpp @@ -635,6 +635,8 @@ bool TextureData::upload(GLuint *textureId, { if (isNull() || !textureId) return false; + if (!format) + format = this->format(); if (isMultisampleTarget(mTarget)) { QOpenGLFunctions_3_3_Core gl; @@ -646,19 +648,18 @@ bool TextureData::upload(GLuint *textureId, } Q_ASSERT(glGetError() == GL_NO_ERROR); - const auto originalFormat = mKtxTexture->glInternalformat; - if (format) - mKtxTexture->glInternalformat = static_cast(format); - #if defined(_WIN32) initializeKtxOpenGLFunctions(); #endif + + const auto originalFormat = mKtxTexture->glInternalformat; + mKtxTexture->glInternalformat = static_cast(format); auto target = static_cast(mTarget); auto error = GLenum{ }; const auto result = (ktxTexture_GLUpload( mKtxTexture.get(), textureId, &target, &error) == KTX_SUCCESS); - mKtxTexture->glInternalformat = originalFormat; + Q_ASSERT(glGetError() == GL_NO_ERROR); return result; } diff --git a/src/editors/SourceEditor.cpp b/src/editors/SourceEditor.cpp index a0c17b55..89f16ae4 100644 --- a/src/editors/SourceEditor.cpp +++ b/src/editors/SourceEditor.cpp @@ -80,7 +80,7 @@ SourceEditor::SourceEditor(QString fileName, FindReplaceBar *findReplaceBar, QWi updateViewportMargins(); updateExtraSelections(); - updateColors(); + updateColors(settings.darkTheme()); setSourceTypeFromExtension(); setPlainText(document()->toPlainText()); } @@ -214,18 +214,16 @@ void SourceEditor::setSourceType(SourceType sourceType) } } -void SourceEditor::updateColors() +void SourceEditor::updateColors(bool darkTheme) { mCurrentLineFormat.setProperty(QTextFormat::FullWidthSelection, true); - mCurrentLineFormat.setBackground(palette().base().color().darker(105)); + mCurrentLineFormat.setBackground(palette().base().color().lighter(darkTheme ? 110 : 95)); - mOccurrencesFormat.setProperty(QTextFormat::OutlinePen, - QPen(palette().highlight().color())); - mOccurrencesFormat.setBackground(palette().base().color().darker(110)); + mOccurrencesFormat.setForeground(palette().text().color().lighter(darkTheme ? 120 : 90)); + mOccurrencesFormat.setBackground(palette().base().color().lighter(darkTheme ? 120 : 90)); auto window = palette().window().color(); - mLineNumberColor = (window.value() < 128 ? - window.lighter(150) : window.darker(150)); + mLineNumberColor = window.darker(window.value() < 128 ? 50 : 150); updateExtraSelections(); } diff --git a/src/editors/SourceEditor.h b/src/editors/SourceEditor.h index 3b2add6a..28c2a8c8 100644 --- a/src/editors/SourceEditor.h +++ b/src/editors/SourceEditor.h @@ -72,7 +72,7 @@ class SourceEditor : public QPlainTextEdit, public IEditor void insertCompletion(const QString &completion); void findReplaceAction(FindReplaceBar::Action action, QString find, QString replace, QTextDocument::FindFlags flags); - void updateColors(); + void updateColors(bool darkTheme); void updateSyntaxHighlighting(); QString mFileName; diff --git a/src/editors/TextureItem.cpp b/src/editors/TextureItem.cpp index 8cde4161..0baa0bdf 100644 --- a/src/editors/TextureItem.cpp +++ b/src/editors/TextureItem.cpp @@ -150,24 +150,29 @@ class ZeroCopyContext : public QObject private: using ProgramKey = std::tuple; + void handleDebugMessage(const QOpenGLDebugMessage &message); QOpenGLFunctions_3_3_Core mGL; QOpenGLDebugLogger mDebugLogger; std::map mPrograms; - bool mInitialized{ }; - - void initialize(); - void handleDebugMessage(const QOpenGLDebugMessage &message); }; ZeroCopyContext::ZeroCopyContext(QObject *parent) : QObject(parent) { + mGL.initializeOpenGLFunctions(); + + if (mDebugLogger.initialize()) { + mDebugLogger.disableMessages(QOpenGLDebugMessage::AnySource, + QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity); + QObject::connect(&mDebugLogger, &QOpenGLDebugLogger::messageLogged, + this, &ZeroCopyContext::handleDebugMessage); + mDebugLogger.startLogging(QOpenGLDebugLogger::SynchronousLogging); + } } QOpenGLFunctions_3_3_Core &ZeroCopyContext::gl() { - initialize(); return mGL; } @@ -184,22 +189,6 @@ QOpenGLShaderProgram *ZeroCopyContext::getProgram(QOpenGLTexture::Target target, return &program; } -void ZeroCopyContext::initialize() -{ - if (std::exchange(mInitialized, true)) - return; - - mGL.initializeOpenGLFunctions(); - - if (mDebugLogger.initialize()) { - mDebugLogger.disableMessages(QOpenGLDebugMessage::AnySource, - QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity); - QObject::connect(&mDebugLogger, &QOpenGLDebugLogger::messageLogged, - this, &ZeroCopyContext::handleDebugMessage); - mDebugLogger.startLogging(QOpenGLDebugLogger::SynchronousLogging); - } -} - void ZeroCopyContext::handleDebugMessage(const QOpenGLDebugMessage &message) { const auto text = message.message(); @@ -269,9 +258,6 @@ void TextureItem::paint(QPainter *painter, 2 * -(x * scale + width / 2) / width, 2 * (y * scale + height / 2) / height); - if (!mContext) - mContext.reset(new ZeroCopyContext()); - if (updateTexture()) renderTexture(transform); @@ -279,14 +265,20 @@ void TextureItem::paint(QPainter *painter, painter->endNativePainting(); } +ZeroCopyContext &TextureItem::context() +{ + if (!mContext) + mContext.reset(new ZeroCopyContext()); + return *mContext; +} + bool TextureItem::updateTexture() { if (!mPreviewTextureId && std::exchange(mUpload, false)) { // upload/replace texture - if (!mImage.upload(&mImageTextureId)) { - mContext->gl().glDeleteTextures(1, &mImageTextureId); - mImageTextureId = GL_NONE; - } + context().gl().glDeleteTextures(1, &mImageTextureId); + mImageTextureId = GL_NONE; + mImage.upload(&mImageTextureId); // last version is deleted in QGraphicsView destructor } return (mPreviewTextureId || mImageTextureId); @@ -295,7 +287,7 @@ bool TextureItem::updateTexture() bool TextureItem::renderTexture(const QMatrix &transform) { Q_ASSERT(glGetError() == GL_NO_ERROR); - auto &gl = mContext->gl(); + auto &gl = context().gl(); auto target = mImage.target(); if (mPreviewTextureId) { @@ -317,7 +309,7 @@ bool TextureItem::renderTexture(const QMatrix &transform) gl.glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl.glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl.glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - if (mImage.levels() > 1) { + if (mMagnifyLinear && mImage.levels() > 1) { gl.glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl.glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } @@ -327,7 +319,7 @@ bool TextureItem::renderTexture(const QMatrix &transform) } } - if (auto *program = mContext->getProgram(target, mImage.format())) { + if (auto *program = context().getProgram(target, mImage.format())) { program->bind(); program->setUniformValue("uTexture", 0); program->setUniformValue("uTransform", transform); diff --git a/src/editors/TextureItem.h b/src/editors/TextureItem.h index 02d7450e..588e86fa 100644 --- a/src/editors/TextureItem.h +++ b/src/editors/TextureItem.h @@ -29,6 +29,7 @@ class TextureItem : public QGraphicsItem void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override; private: + ZeroCopyContext &context(); bool updateTexture(); bool renderTexture(const QMatrix &transform);