From 77aca17dcc103fdce7ce629635def8432886370a Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:52:06 +0200 Subject: [PATCH] feat: add animation --- CMakeLists.txt | 3 +- QodeAssistClient.hpp | 2 +- .../CompletionProgressHandler.cpp | 26 ++-- .../CompletionProgressHandler.hpp | 3 +- widgets/ProgressWidget.cpp | 114 ++++++++++++++++++ widgets/ProgressWidget.hpp | 48 ++++++++ 6 files changed, 183 insertions(+), 13 deletions(-) rename CompletionProgressHandler.cpp => widgets/CompletionProgressHandler.cpp (80%) rename CompletionProgressHandler.hpp => widgets/CompletionProgressHandler.hpp (95%) create mode 100644 widgets/ProgressWidget.cpp create mode 100644 widgets/ProgressWidget.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bf6a0ba..3947fe8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,6 @@ add_qtc_plugin(QodeAssist qodeassist.cpp QodeAssistConstants.hpp QodeAssisttr.h - CompletionProgressHandler.hpp CompletionProgressHandler.cpp LLMClientInterface.hpp LLMClientInterface.cpp templates/Templates.hpp templates/CodeLlamaFim.hpp @@ -102,6 +101,8 @@ add_qtc_plugin(QodeAssist ConfigurationManager.hpp ConfigurationManager.cpp CodeHandler.hpp CodeHandler.cpp UpdateStatusWidget.hpp UpdateStatusWidget.cpp + widgets/CompletionProgressHandler.hpp widgets/CompletionProgressHandler.cpp + widgets/ProgressWidget.hpp widgets/ProgressWidget.cpp ) get_target_property(QtCreatorCorePath QtCreator::Core LOCATION) diff --git a/QodeAssistClient.hpp b/QodeAssistClient.hpp index 330021f..effdd80 100644 --- a/QodeAssistClient.hpp +++ b/QodeAssistClient.hpp @@ -24,9 +24,9 @@ #pragma once -#include "CompletionProgressHandler.hpp" #include "LLMClientInterface.hpp" #include "LSPCompletion.hpp" +#include "widgets/CompletionProgressHandler.hpp" #include #include #include diff --git a/CompletionProgressHandler.cpp b/widgets/CompletionProgressHandler.cpp similarity index 80% rename from CompletionProgressHandler.cpp rename to widgets/CompletionProgressHandler.cpp index 8b21f1f..1fd3046 100644 --- a/CompletionProgressHandler.cpp +++ b/widgets/CompletionProgressHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Petr Mironychev + * Copyright (C) 2025 Petr Mironychev * * This file is part of QodeAssist. * @@ -18,9 +18,20 @@ */ #include "CompletionProgressHandler.hpp" -#include -#include + +#include +#include +#include #include +#include +#include + +#include +#include +#include +#include + +#include "ProgressWidget.hpp" namespace QodeAssist { @@ -30,7 +41,6 @@ void CompletionProgressHandler::showProgress(TextEditor::TextEditorWidget *widge m_isActive = true; if (m_widget) { - // Используем тот же метод получения позиции что и в TextSuggestion const QRect cursorRect = m_widget->cursorRect(m_widget->textCursor()); m_iconPosition = m_widget->viewport()->mapToGlobal(cursorRect.topLeft()) - Utils::ToolTip::offsetFromPosition(); @@ -65,14 +75,12 @@ void CompletionProgressHandler::operateTooltip( if (!m_isActive || !editorWidget) return; - auto progressLabel = new QLabel; - progressLabel->setPixmap(QPixmap(":/resources/images/qoderassist-icon.png") - .scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + auto progressWidget = new ProgressWidget(editorWidget); QPoint showPoint = point; - showPoint.ry() -= progressLabel->sizeHint().height(); + showPoint.ry() -= progressWidget->height(); - Utils::ToolTip::show(showPoint, progressLabel, editorWidget); + Utils::ToolTip::show(showPoint, progressWidget, editorWidget); } } // namespace QodeAssist diff --git a/CompletionProgressHandler.hpp b/widgets/CompletionProgressHandler.hpp similarity index 95% rename from CompletionProgressHandler.hpp rename to widgets/CompletionProgressHandler.hpp index 85948fb..2d012e4 100644 --- a/CompletionProgressHandler.hpp +++ b/widgets/CompletionProgressHandler.hpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Petr Mironychev + * Copyright (C) 2025 Petr Mironychev * * This file is part of QodeAssist. * @@ -29,7 +29,6 @@ class CompletionProgressHandler : public TextEditor::BaseHoverHandler public: void showProgress(TextEditor::TextEditorWidget *widget); void hideProgress(); - void abort() override {} protected: void identifyMatch( diff --git a/widgets/ProgressWidget.cpp b/widgets/ProgressWidget.cpp new file mode 100644 index 0000000..2e4b207 --- /dev/null +++ b/widgets/ProgressWidget.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2025 Petr Mironychev + * + * This file is part of QodeAssist. + * + * QodeAssist is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QodeAssist is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QodeAssist. If not, see . + */ + +#include "ProgressWidget.hpp" + +namespace QodeAssist { + +ProgressWidget::ProgressWidget(QWidget *parent) + : QWidget(parent) +{ + m_dotPosition = 0; + m_timer.setInterval(300); + connect(&m_timer, &QTimer::timeout, this, [this]() { + m_dotPosition = (m_dotPosition + 1) % 4; + update(); + }); + m_timer.start(); + + m_textColor = Utils::creatorTheme()->color(Utils::Theme::TextColorNormal); + m_backgroundColor = Utils::creatorTheme()->color(Utils::Theme::BackgroundColorNormal); + + m_logoPixmap = QPixmap(":/resources/images/qoderassist-icon.png"); + + if (!m_logoPixmap.isNull()) { + QImage image = m_logoPixmap.toImage(); + image = image.convertToFormat(QImage::Format_ARGB32); + + for (int y = 0; y < image.height(); ++y) { + for (int x = 0; x < image.width(); ++x) { + QColor pixelColor = QColor::fromRgba(image.pixel(x, y)); + + int brightness = (pixelColor.red() + pixelColor.green() + pixelColor.blue()) / 3; + + if (brightness > 200) { + pixelColor.setAlpha(0); + image.setPixelColor(x, y, pixelColor); + } else if (pixelColor.alpha() > 0) { + int alpha = pixelColor.alpha(); + pixelColor = m_textColor; + pixelColor.setAlpha(alpha); + image.setPixelColor(x, y, pixelColor); + } + } + } + + m_logoPixmap = QPixmap::fromImage(image); + m_logoPixmap = m_logoPixmap.scaled(24, 24, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + + setFixedSize(40, 40); +} + +ProgressWidget::~ProgressWidget() +{ + m_timer.stop(); +} + +void ProgressWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + painter.fillRect(rect(), m_backgroundColor); + + if (!m_logoPixmap.isNull()) { + QRect logoRect( + (width() - m_logoPixmap.width()) / 2, 5, m_logoPixmap.width(), m_logoPixmap.height()); + painter.drawPixmap(logoRect, m_logoPixmap); + } + + int dotSpacing = 6; + int dotSize = 4; + int totalDotWidth = 3 * dotSize + 2 * dotSpacing; + int startX = (width() - totalDotWidth) / 2; + int dotY = height() - 8; + + for (int i = 0; i < 3; ++i) { + QColor dotColor = m_textColor; + + if (m_dotPosition == 0) { + dotColor.setAlpha(128); + } else { + if (i == m_dotPosition - 1) { + dotColor.setAlpha(255); + } else { + dotColor.setAlpha(80); + } + } + + painter.setPen(Qt::NoPen); + painter.setBrush(dotColor); + + int x = startX + i * (dotSize + dotSpacing); + painter.drawEllipse(x, dotY, dotSize, dotSize); + } +} + +} // namespace QodeAssist diff --git a/widgets/ProgressWidget.hpp b/widgets/ProgressWidget.hpp new file mode 100644 index 0000000..27f0b13 --- /dev/null +++ b/widgets/ProgressWidget.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2025 Petr Mironychev + * + * This file is part of QodeAssist. + * + * QodeAssist is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QodeAssist is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QodeAssist. If not, see . + */ + +#pragma once + +#include +#include +#include + +#include +#include + +namespace QodeAssist { + +class ProgressWidget : public QWidget +{ +public: + ProgressWidget(QWidget *parent = nullptr); + ~ProgressWidget(); + +protected: + void paintEvent(QPaintEvent *) override; + +private: + QTimer m_timer; + int m_dotPosition; + QColor m_textColor; + QColor m_backgroundColor; + QPixmap m_logoPixmap; +}; + +} // namespace QodeAssist