mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-07-24 20:20:59 -04:00
feat: add support code completion via acp
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#include "CompletionHintHandler.hpp"
|
||||
#include "CompletionHintWidget.hpp"
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
CompletionHintHandler::CompletionHintHandler() = default;
|
||||
|
||||
CompletionHintHandler::~CompletionHintHandler()
|
||||
{
|
||||
hideHint();
|
||||
}
|
||||
|
||||
void CompletionHintHandler::showHint(TextEditor::TextEditorWidget *widget, QPoint position, int fontSize)
|
||||
{
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_hintWidget) {
|
||||
m_hintWidget = new CompletionHintWidget(widget, fontSize);
|
||||
}
|
||||
|
||||
m_hintWidget->move(position);
|
||||
m_hintWidget->show();
|
||||
m_hintWidget->raise();
|
||||
}
|
||||
|
||||
void CompletionHintHandler::hideHint()
|
||||
{
|
||||
if (m_hintWidget) {
|
||||
m_hintWidget->deleteLater();
|
||||
m_hintWidget = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool CompletionHintHandler::isHintVisible() const
|
||||
{
|
||||
return !m_hintWidget.isNull() && m_hintWidget->isVisible();
|
||||
}
|
||||
|
||||
void CompletionHintHandler::updateHintPosition(TextEditor::TextEditorWidget *widget, QPoint position)
|
||||
{
|
||||
if (!widget || !m_hintWidget) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_hintWidget->move(position);
|
||||
}
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QPointer>
|
||||
#include <functional>
|
||||
|
||||
namespace TextEditor {
|
||||
class TextEditorWidget;
|
||||
}
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
class CompletionHintWidget;
|
||||
|
||||
class CompletionHintHandler
|
||||
{
|
||||
public:
|
||||
CompletionHintHandler();
|
||||
~CompletionHintHandler();
|
||||
|
||||
void showHint(TextEditor::TextEditorWidget *widget, QPoint position, int fontSize);
|
||||
void hideHint();
|
||||
bool isHintVisible() const;
|
||||
void updateHintPosition(TextEditor::TextEditorWidget *widget, QPoint position);
|
||||
|
||||
private:
|
||||
QPointer<CompletionHintWidget> m_hintWidget;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#include "CompletionHintWidget.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
CompletionHintWidget::CompletionHintWidget(QWidget *parent, int fontSize)
|
||||
: QWidget(parent)
|
||||
, m_isHovered(false)
|
||||
{
|
||||
m_accentColor = Utils::creatorTheme()->color(Utils::Theme::TextColorNormal);
|
||||
|
||||
setMouseTracking(true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
int triangleSize = qMax(6, fontSize / 2);
|
||||
setFixedSize(triangleSize, triangleSize);
|
||||
}
|
||||
|
||||
void CompletionHintWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QColor triangleColor = m_accentColor;
|
||||
triangleColor.setAlpha(m_isHovered ? 255 : 200);
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(triangleColor);
|
||||
|
||||
QPolygonF triangle;
|
||||
int w = width();
|
||||
int h = height();
|
||||
|
||||
triangle << QPointF(0, 0)
|
||||
<< QPointF(0, h)
|
||||
<< QPointF(w, h / 2.0);
|
||||
|
||||
painter.drawPolygon(triangle);
|
||||
}
|
||||
|
||||
void CompletionHintWidget::enterEvent(QEnterEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
m_isHovered = true;
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
update();
|
||||
}
|
||||
|
||||
void CompletionHintWidget::leaveEvent(QEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
m_isHovered = false;
|
||||
setCursor(Qt::ArrowCursor);
|
||||
update();
|
||||
}
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
class CompletionHintWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CompletionHintWidget(QWidget *parent = nullptr, int fontSize = 12);
|
||||
~CompletionHintWidget() override = default;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void enterEvent(QEnterEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
QColor m_accentColor;
|
||||
bool m_isHovered;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#include "EditorChatButton.hpp"
|
||||
|
||||
#include <utils/theme/theme.h>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
EditorChatButton::EditorChatButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
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);
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
setToolTip(tr("Open QodeAssist Chat"));
|
||||
}
|
||||
|
||||
EditorChatButton::~EditorChatButton() = default;
|
||||
|
||||
void EditorChatButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QColor bgColor = m_backgroundColor;
|
||||
if (m_isPressed) {
|
||||
bgColor = bgColor.darker(120);
|
||||
} else if (m_isHovered) {
|
||||
bgColor = bgColor.lighter(110);
|
||||
}
|
||||
painter.fillRect(rect(), bgColor);
|
||||
|
||||
QRect buttonRect = rect().adjusted(4, 4, -4, -4);
|
||||
painter.setPen(Qt::NoPen);
|
||||
QColor buttonBgColor
|
||||
= m_isPressed ? Utils::creatorTheme()->color(Utils::Theme::BackgroundColorHover).darker(110)
|
||||
: Utils::creatorTheme()->color(Utils::Theme::BackgroundColorHover);
|
||||
|
||||
if (m_isHovered) {
|
||||
buttonBgColor = buttonBgColor.lighter(110);
|
||||
}
|
||||
painter.setBrush(buttonBgColor);
|
||||
painter.drawEllipse(buttonRect);
|
||||
|
||||
if (!m_logoPixmap.isNull()) {
|
||||
QRect logoRect(
|
||||
(width() - m_logoPixmap.width()) / 2,
|
||||
(height() - m_logoPixmap.height()) / 2,
|
||||
m_logoPixmap.width(),
|
||||
m_logoPixmap.height());
|
||||
painter.drawPixmap(logoRect, m_logoPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorChatButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_isPressed = true;
|
||||
update();
|
||||
}
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void EditorChatButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && m_isPressed) {
|
||||
m_isPressed = false;
|
||||
update();
|
||||
if (rect().contains(event->pos())) {
|
||||
emit clicked();
|
||||
}
|
||||
}
|
||||
QWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void EditorChatButton::enterEvent(QEnterEvent *event)
|
||||
{
|
||||
m_isHovered = true;
|
||||
update();
|
||||
QWidget::enterEvent(event);
|
||||
}
|
||||
|
||||
void EditorChatButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
m_isHovered = false;
|
||||
m_isPressed = false;
|
||||
update();
|
||||
QWidget::leaveEvent(event);
|
||||
}
|
||||
|
||||
} // namespace QodeAssist
|
||||
@@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
class EditorChatButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EditorChatButton(QWidget *parent = nullptr);
|
||||
~EditorChatButton() override;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void enterEvent(QEnterEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
QPixmap m_logoPixmap;
|
||||
QColor m_textColor;
|
||||
QColor m_backgroundColor;
|
||||
bool m_isPressed = false;
|
||||
bool m_isHovered = false;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#include "EditorChatButtonHandler.hpp"
|
||||
#include "EditorChatButton.hpp"
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
#include <QPoint>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
EditorChatButtonHandler::~EditorChatButtonHandler()
|
||||
{
|
||||
delete m_chatButton;
|
||||
}
|
||||
|
||||
void EditorChatButtonHandler::showButton(TextEditor::TextEditorWidget *widget)
|
||||
{
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
m_widget = widget;
|
||||
|
||||
identifyMatch(widget, widget->textCursor().position(), [this](auto priority) {
|
||||
if (priority != Priority_None && m_widget) {
|
||||
const QTextCursor cursor = m_widget->textCursor();
|
||||
const QRect selectionRect = m_widget->cursorRect(cursor);
|
||||
m_cursorPosition = m_widget->viewport()->mapToGlobal(selectionRect.topLeft())
|
||||
- Utils::ToolTip::offsetFromPosition();
|
||||
operateTooltip(m_widget, m_cursorPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void EditorChatButtonHandler::hideButton()
|
||||
{
|
||||
Utils::ToolTip::hide();
|
||||
}
|
||||
|
||||
void EditorChatButtonHandler::identifyMatch(
|
||||
TextEditor::TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
||||
{
|
||||
if (!editorWidget) {
|
||||
report(Priority_None);
|
||||
return;
|
||||
}
|
||||
|
||||
report(Priority_Tooltip);
|
||||
}
|
||||
|
||||
void EditorChatButtonHandler::operateTooltip(
|
||||
TextEditor::TextEditorWidget *editorWidget, const QPoint &point)
|
||||
{
|
||||
if (!editorWidget)
|
||||
return;
|
||||
|
||||
if (!Utils::ToolTip::isVisible()) {
|
||||
m_chatButton = new EditorChatButton(editorWidget);
|
||||
m_buttonHeight = m_chatButton->height();
|
||||
|
||||
QPoint showPoint = point;
|
||||
showPoint.ry() -= m_buttonHeight;
|
||||
|
||||
Utils::ToolTip::show(showPoint, m_chatButton, editorWidget);
|
||||
} else {
|
||||
QPoint showPoint = point;
|
||||
showPoint.ry() -= m_buttonHeight;
|
||||
Utils::ToolTip::move(showPoint);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QodeAssist
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "widgets/EditorChatButton.hpp"
|
||||
#include <texteditor/basehoverhandler.h>
|
||||
#include <QPointer>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
class EditorChatButtonHandler : public TextEditor::BaseHoverHandler
|
||||
{
|
||||
public:
|
||||
explicit EditorChatButtonHandler() = default;
|
||||
~EditorChatButtonHandler() override;
|
||||
|
||||
void showButton(TextEditor::TextEditorWidget *widget);
|
||||
void hideButton();
|
||||
|
||||
signals:
|
||||
void chatButtonClicked(TextEditor::TextEditorWidget *widget);
|
||||
|
||||
protected:
|
||||
void identifyMatch(
|
||||
TextEditor::TextEditorWidget *editorWidget, int pos, ReportPriority report) override;
|
||||
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point) override;
|
||||
|
||||
private:
|
||||
QPointer<TextEditor::TextEditorWidget> m_widget;
|
||||
QPoint m_cursorPosition;
|
||||
EditorChatButton *m_chatButton = nullptr;
|
||||
int m_buttonHeight = 0;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist
|
||||
Reference in New Issue
Block a user