Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [symbolbar] Fix issue of UI #866

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/plugins/codeeditor/gui/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void TabWidgetPrivate::initUI()

tabBar = new TabBar(q);
symbolBar = new SymbolBar(q);
symbolBar->setVisible(false);

mainLayout->addWidget(tabBar, 0, Qt::AlignTop);
mainLayout->addWidget(symbolBar, 0, Qt::AlignTop);
Expand Down Expand Up @@ -387,6 +388,7 @@ void TabWidgetPrivate::onTabClosed(const QString &fileName)

if (editorMng.isEmpty()) {
symbolBar->clear();
symbolBar->setVisible(false);
q->setSplitButtonVisible(false);
emit q->closeRequested();
}
Expand Down Expand Up @@ -887,6 +889,7 @@ void TabWidget::openFile(const QString &fileName)
Inotify::globalInstance()->addPath(fileName);

d->symbolBar->setPath(fileName);
d->symbolBar->setVisible(true);
d->tabBar->setFileName(fileName);
TextEditor *editor = d->createEditor(fileName);

Expand Down
1 change: 1 addition & 0 deletions src/plugins/codeeditor/lsp/lspclientmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ QColor LSPClientManager::highlightColor(const QString &langId, lsp::SemanticToke
? QColor("#000000")
: QColor("#d6cf9a");

QMutexLocker lk(&dataMutex);
if (!styleMap.contains(langId)) {
const auto &filePath = support_file::EditorStyle::globalPath(langId);
StyleSettings settings;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/codeeditor/lsp/lspclientmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class LSPClientManager

QHash<newlsp::ProjectKey, newlsp::Client *> clientHash;
QMap<QString, StyleSettings> styleMap;
QMutex dataMutex;
};

#endif // LSPCLIENTMANAGER_H
43 changes: 23 additions & 20 deletions src/plugins/codeeditor/symbol/symbolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void CurmbItem::setText(const QString &text)
{
displayText = text;
auto rect = fontMetrics().boundingRect(text);
int w = rect.width() + qCeil(font().pixelSize() / 10);
int w = rect.width() + qCeil(static_cast<qreal>(font().pixelSize()) / 10);
if (!isRoot())
w += spacing + SeparatorSize;
w += spacing + SeparatorSize + 1;

setFixedWidth(w);
setFixedHeight(rect.height());
Expand Down Expand Up @@ -155,14 +155,20 @@ void CurmbItem::paintEvent(QPaintEvent *event)
}

SymbolBar::SymbolBar(QWidget *parent)
: QWidget(parent)
: QScrollArea(parent)
{
setAutoFillBackground(true);
setBackgroundRole(QPalette::Base);
setWidgetResizable(true);
setFrameShape(QFrame::NoFrame);
setFixedHeight(30);

QWidget *widget = new QWidget(this);
mainLayout = new QHBoxLayout(widget);
mainLayout->setContentsMargins(10, 0, 0, 0);
mainLayout->setSpacing(4);

auto layout = new QHBoxLayout(this);
layout->setContentsMargins(10, 0, 0, 0);
layout->setSpacing(4);
setWidget(widget);
}

void SymbolBar::setPath(const QString &path)
Expand All @@ -183,27 +189,26 @@ void SymbolBar::setPath(const QString &path)
}
}

auto layout = qobject_cast<QHBoxLayout *>(this->layout());
auto itemList = displayPath.split(QDir::separator(), QString::SkipEmptyParts);
for (int i = 0; i < itemList.size(); ++i) {
CurmbItem *item = new CurmbItem(CurmbItem::FilePath, i, this);
setFixedHeight(item->height());
item->setText(itemList[i]);
item->setToolTip(path);
if (i == itemList.size() - 1)
item->setIcon(DFileIconProvider::globalProvider()->icon(path));

QString filePath = workspaceDir + QDir::separator() + itemList.mid(0, i + 1).join(QDir::separator());
item->setUserData(filePath);
layout->addWidget(item, 0, Qt::AlignVCenter | Qt::AlignLeft);
mainLayout->addWidget(item, 0, Qt::AlignVCenter | Qt::AlignLeft);
connect(item, &CurmbItem::clicked, this, &SymbolBar::curmbItemClicked);
}
layout->addStretch(1);
mainLayout->addStretch(1);
}

void SymbolBar::clear()
{
auto layout = qobject_cast<QHBoxLayout *>(this->layout());
while (QLayoutItem *item = layout->takeAt(0)) {
while (QLayoutItem *item = mainLayout->takeAt(0)) {
if (QWidget *widget = item->widget())
delete widget;
delete item;
Expand All @@ -223,12 +228,11 @@ void SymbolBar::updateSymbol(int line, int index)
return;

if (!symbolItem) {
auto layout = qobject_cast<QHBoxLayout *>(this->layout());
if (layout->count() < 1)
if (mainLayout->count() < 1)
return;

symbolItem = new CurmbItem(CurmbItem::Symbol, layout->count() - 1, this);
layout->insertWidget(layout->count() - 1, symbolItem);
symbolItem = new CurmbItem(CurmbItem::Symbol, mainLayout->count() - 1, this);
mainLayout->insertWidget(mainLayout->count() - 1, symbolItem);
connect(symbolItem, &CurmbItem::clicked, this, &SymbolBar::curmbItemClicked);
}

Expand All @@ -253,8 +257,8 @@ void SymbolBar::curmbItemClicked()
connect(symbolView, &SymbolView::hidden, this, &SymbolBar::resetCurmbItemState);
}

auto rect = item->geometry();
auto pos = mapToGlobal(rect.bottomLeft());
auto rect = item->rect();
auto pos = item->mapToGlobal(rect.bottomLeft());

switch (item->curmbType()) {
case CurmbItem::FilePath: {
Expand All @@ -278,9 +282,8 @@ void SymbolBar::curmbItemClicked()

void SymbolBar::resetCurmbItemState()
{
auto layout = qobject_cast<QHBoxLayout *>(this->layout());
for (int i = 0; i < layout->count(); ++i) {
auto item = layout->itemAt(i);
for (int i = 0; i < mainLayout->count(); ++i) {
auto item = mainLayout->itemAt(i);
if (!item)
continue;

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/codeeditor/symbol/symbolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define SYMBOLBAR_H

#include <QVariant>
#include <QWidget>
#include <QScrollArea>
#include <QIcon>

class CurmbItem : public QWidget
Expand Down Expand Up @@ -51,7 +51,8 @@ class CurmbItem : public QWidget
};

class SymbolView;
class SymbolBar : public QWidget
class QHBoxLayout;
class SymbolBar : public QScrollArea
{
Q_OBJECT
public:
Expand All @@ -68,6 +69,7 @@ public Q_SLOTS:
private:
CurmbItem *symbolItem { nullptr };
SymbolView *symbolView { nullptr };
QHBoxLayout *mainLayout { nullptr };
};

#endif // SYMBOLBAR_H
Loading