Skip to content

Commit

Permalink
fix: window flashing.
Browse files Browse the repository at this point in the history
Change-Id: I104b180f9143d1909188e9b67fbbeeca9c4d5747
rekols committed Aug 9, 2018
1 parent c370010 commit c55c5e4
Showing 4 changed files with 75 additions and 75 deletions.
3 changes: 1 addition & 2 deletions deepin-editor.desktop
Original file line number Diff line number Diff line change
@@ -7,5 +7,4 @@ Icon=deepin-editor
MimeType=text/plain;text/html;text/x-php;text/x-c;text/x-shellscript;
Name=Deepin Editor
Type=Application


StartupNotify=true
26 changes: 13 additions & 13 deletions editor/src/startmanager.cpp
Original file line number Diff line number Diff line change
@@ -74,19 +74,19 @@ void StartManager::openFilesInTab(QStringList files)

QDir readonlyDirectory = QDir(QDir(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first()).filePath("readonly-files"));
QStringList readonlyFiles = readonlyDirectory.entryList(QStringList(), QDir::Files);

Window *window = createWindow(true);

// Open blank files of last session.
if (blankFiles.size() > 0 || readonlyFiles.size() > 0) {
foreach(QString blankFile, blankFiles) {
window->addBlankTab(QDir(blankDirectory).filePath(blankFile));
}

foreach(QString readonlyFile, readonlyFiles) {
QString readonlyFilePath = QDir(readonlyDirectory).filePath(readonlyFile);
QString realpath = QFileInfo(readonlyFilePath).fileName().replace(" !_! ", QDir().separator());

window->addTab(realpath);
}
}
@@ -106,19 +106,19 @@ void StartManager::openFilesInTab(QStringList files)
// Open exist tab if file has opened.
if (info.windowIndex != -1) {
popupExistTabs(info);

qDebug() << "Open " << file << " in exist tab";
}
// Create new window with file if haven't window exist.
else if (m_windows.size() == 0) {
createWindow(true)->addTab(file);

qDebug() << "Open " << file << " with new window";
}
// Open file tab in first window of window list.
else {
m_windows[0]->addTab(file);

qDebug() << "Open " << file << " in first window";
}

@@ -136,26 +136,26 @@ Window* StartManager::createWindow(bool alwaysCenter)
// Create window.
Window *window = new Window();
connect(window, &Window::dropTabOut, this, &StartManager::createWindowFromTab, Qt::QueuedConnection);

// Quit application if close last window.
connect(window, &Window::close, this,
connect(window, &Window::close, this,
[=]() {
int windowIndex = m_windows.indexOf(window);
qDebug() << "Close window " << windowIndex;

if (windowIndex >= 0) {
m_windows.takeAt(windowIndex);
}

if (m_windows.size() <= 0) {
QApplication::quit();
}
});

// Init window position.
initWindowPosition(window, alwaysCenter);
connect(window, &Window::newWindow, this,

connect(window, &Window::newWindow, this,
[=] () {
openFilesInWindow(QStringList());
});
@@ -187,7 +187,7 @@ StartManager::FileTabInfo StartManager::getFileTabInfo(QString file)
FileTabInfo info = {-1, -1};

qDebug() << "Windows size: " << m_windows.size();

foreach (Window *window, m_windows) {
int tabIndex = window->getTabIndex(file);
if (tabIndex >= 0) {
102 changes: 52 additions & 50 deletions editor/src/window.cpp
Original file line number Diff line number Diff line change
@@ -52,7 +52,15 @@

DWM_USE_NAMESPACE

Window::Window(DMainWindow *parent) : DMainWindow(parent)
Window::Window(DMainWindow *parent)
: DMainWindow(parent),
m_findBar(new FindBar),
m_jumpLineBar(new JumpLineBar(this)),
m_replaceBar(new ReplaceBar),
m_settings(new Settings(this)),
m_tabbar(new Tabbar),
m_menu(new QMenu),
m_themeBar(new ThemeBar(this))
{
// Init.
installEventFilter(this); // add event filter
@@ -63,7 +71,6 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
autoSaveDBus = new DBusDaemon::dbus("com.deepin.editor.daemon", "/", QDBusConnection::systemBus(), this);

// Init settings.
m_settings = new Settings(this);
connect(m_settings, &Settings::adjustFont, this, &Window::updateFont);
connect(m_settings, &Settings::adjustFontSize, this, &Window::updateFontSize);
connect(m_settings, &Settings::adjustTabSpaceNumber, this, &Window::updateTabSpaceNumber);
@@ -94,12 +101,11 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
});

// Init titlebar.
if (this->titlebar()) {
if (titlebar()) {
// Init tabbar.
m_tabbar = new Tabbar();
this->titlebar()->setCustomWidget(m_tabbar, Qt::AlignVCenter, false);
this->titlebar()->setSeparatorVisible(true);
this->titlebar()->setAutoHideOnFullscreen(true);
titlebar()->setCustomWidget(m_tabbar, Qt::AlignVCenter, false);
titlebar()->setSeparatorVisible(true);
titlebar()->setAutoHideOnFullscreen(true);

connect(m_tabbar, &Tabbar::doubleClicked, this->titlebar(), &DTitlebar::doubleClicked, Qt::QueuedConnection);
connect(m_tabbar, &Tabbar::switchToFile, this, &Window::handleSwitchToFile, Qt::QueuedConnection);
@@ -122,7 +128,6 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
}
});

m_menu = new QMenu();
m_menu->setStyle(QStyleFactory::create("dlight"));

// Init main menu.
@@ -147,6 +152,11 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
m_menu->addAction(m_settingAction);
this->titlebar()->setMenu(m_menu);

// Apply qss theme.
Utils::applyQss(this, "main.qss");
m_titlebarStyleSheet = this->titlebar()->styleSheet();
loadTheme(m_themeName);

connect(m_newWindowAction, &QAction::triggered, this, &Window::newWindow);
connect(m_newTabAction, &QAction::triggered, this,
[=] () {
@@ -189,7 +199,6 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
});

// Init replace bar.
m_replaceBar = new ReplaceBar();
connect(m_replaceBar, &ReplaceBar::removeSearchKeyword, this, &Window::handleRemoveSearchKeyword, Qt::QueuedConnection);
connect(m_replaceBar, &ReplaceBar::replaceAll, this, &Window::handleReplaceAll, Qt::QueuedConnection);
connect(m_replaceBar, &ReplaceBar::replaceNext, this, &Window::handleReplaceNext, Qt::QueuedConnection);
@@ -201,19 +210,17 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
});

// Init jump line bar.
jumpLineBar = new JumpLineBar(this);
QTimer::singleShot(0, jumpLineBar, SLOT(hide()));
QTimer::singleShot(0, m_jumpLineBar, SLOT(hide()));

connect(jumpLineBar, &JumpLineBar::jumpToLine, this, &Window::handleJumpLineBarJumpToLine, Qt::QueuedConnection);
connect(jumpLineBar, &JumpLineBar::backToPosition, this, &Window::handleBackToPosition, Qt::QueuedConnection);
connect(jumpLineBar, &JumpLineBar::lostFocusExit, this, &Window::handleJumpLineBarExit, Qt::QueuedConnection);
connect(m_jumpLineBar, &JumpLineBar::jumpToLine, this, &Window::handleJumpLineBarJumpToLine, Qt::QueuedConnection);
connect(m_jumpLineBar, &JumpLineBar::backToPosition, this, &Window::handleBackToPosition, Qt::QueuedConnection);
connect(m_jumpLineBar, &JumpLineBar::lostFocusExit, this, &Window::handleJumpLineBarExit, Qt::QueuedConnection);

// Make jump line bar pop at top-right of editor.
DAnchorsBase::setAnchor(jumpLineBar, Qt::AnchorTop, m_layoutWidget, Qt::AnchorTop);
DAnchorsBase::setAnchor(jumpLineBar, Qt::AnchorRight, m_layoutWidget, Qt::AnchorRight);
DAnchorsBase::setAnchor(m_jumpLineBar, Qt::AnchorTop, m_layoutWidget, Qt::AnchorTop);
DAnchorsBase::setAnchor(m_jumpLineBar, Qt::AnchorRight, m_layoutWidget, Qt::AnchorRight);

// Init theme bar.
m_themeBar = new ThemeBar(this);
DAnchorsBase::setAnchor(m_themeBar, Qt::AnchorTop, m_layoutWidget, Qt::AnchorTop);
DAnchorsBase::setAnchor(m_themeBar, Qt::AnchorBottom, m_layoutWidget, Qt::AnchorBottom);
DAnchorsBase::setAnchor(m_themeBar, Qt::AnchorRight, m_layoutWidget, Qt::AnchorRight);
@@ -230,11 +237,6 @@ Window::Window(DMainWindow *parent) : DMainWindow(parent)
(static_cast<ThemeItem*>(item))->setFrameColor(frameSelectedColor, frameNormalColor);
}

// Apply qss theme.
Utils::applyQss(this, "main.qss");
m_titlebarStyleSheet = this->titlebar()->styleSheet();
loadTheme(m_themeName);

// Init words database.
m_wordsDB = QSqlDatabase::addDatabase("QSQLITE");
m_wordsDB.setDatabaseName(WORDS_DB_FILE_PATH);
@@ -691,11 +693,11 @@ void Window::popupReplaceBar()

void Window::popupJumpLineBar()
{
if (jumpLineBar->isVisible()) {
if (jumpLineBar->isFocus()) {
if (m_jumpLineBar->isVisible()) {
if (m_jumpLineBar->isFocus()) {
QTimer::singleShot(0, m_editorMap[m_tabbar->getActiveTabPath()]->textEditor, SLOT(setFocus()));
} else {
jumpLineBar->focus();
m_jumpLineBar->focus();
}
} else {
QString tabPath = m_tabbar->getActiveTabPath();
@@ -706,7 +708,7 @@ void Window::popupJumpLineBar()
int count = editor->textEditor->blockCount();
int scrollOffset = editor->textEditor->getScrollOffset();

jumpLineBar->activeInput(tabPath, row, column, count, scrollOffset);
m_jumpLineBar->activeInput(tabPath, row, column, count, scrollOffset);
}
}

@@ -1380,40 +1382,40 @@ void Window::handleConfirmCompletion()

void Window::loadTheme(const QString &name)
{
foreach (auto editor, m_editorMap.values()) {
editor->textEditor->setThemeWithName(name);
}
for (auto editor : m_editorMap.values()) {
editor->textEditor->setThemeWithName(name);
}

QVariantMap jsonMap = Utils::getThemeNodeMap(name);

auto backgroundColor = jsonMap["editor-colors"].toMap()["background-color"].toString();

if (QColor(backgroundColor).lightness() < 128) {
DThemeManager::instance()->setTheme("dark");
m_tabbar->tabbar->setBackground(m_darkTabBackgroundStartColor, m_darkTabBackgroundEndColor);
changeTitlebarBackground(m_darkTabBackgroundStartColor, m_darkTabBackgroundEndColor);
m_tabbar->tabbar->setBackground(m_darkTabBackgroundStartColor, m_darkTabBackgroundEndColor);
changeTitlebarBackground(m_darkTabBackgroundStartColor, m_darkTabBackgroundEndColor);
} else {
DThemeManager::instance()->setTheme("light");
m_tabbar->tabbar->setBackground(m_lightTabBackgroundStartColor, m_lightTabBackgroundEndColor);
changeTitlebarBackground(m_lightTabBackgroundStartColor, m_lightTabBackgroundEndColor);
}

m_themeBar->setBackground(backgroundColor);
jumpLineBar->setBackground(backgroundColor);
m_replaceBar->setBackground(backgroundColor);
m_findBar->setBackground(backgroundColor);
m_tabbar->tabbar->setDNDColor(jsonMap["app-colors"].toMap()["tab-dnd-start"].toString(), jsonMap["app-colors"].toMap()["tab-dnd-end"].toString());
m_tabbar->setTabActiveColor(jsonMap["app-colors"].toMap()["tab-active"].toString());

auto frameSelectedColor = jsonMap["app-colors"].toMap()["themebar-frame-selected"].toString();
auto frameNormalColor = jsonMap["app-colors"].toMap()["themebar-frame-normal"].toString();
for (DSimpleListItem* item : m_themeBar->items) {
(static_cast<ThemeItem*>(item))->setFrameColor(frameSelectedColor, frameNormalColor);
DThemeManager::instance()->setTheme("light");
m_tabbar->tabbar->setBackground(m_lightTabBackgroundStartColor, m_lightTabBackgroundEndColor);
changeTitlebarBackground(m_lightTabBackgroundStartColor, m_lightTabBackgroundEndColor);
}
m_themeBar->themeView->repaint();

m_settings->settings->option("base.theme.default")->setValue(name);
m_themeName = name;
m_themeBar->setBackground(backgroundColor);
m_jumpLineBar->setBackground(backgroundColor);
m_replaceBar->setBackground(backgroundColor);
m_findBar->setBackground(backgroundColor);
m_tabbar->tabbar->setDNDColor(jsonMap["app-colors"].toMap()["tab-dnd-start"].toString(), jsonMap["app-colors"].toMap()["tab-dnd-end"].toString());
m_tabbar->setTabActiveColor(jsonMap["app-colors"].toMap()["tab-active"].toString());

auto frameSelectedColor = jsonMap["app-colors"].toMap()["themebar-frame-selected"].toString();
auto frameNormalColor = jsonMap["app-colors"].toMap()["themebar-frame-normal"].toString();
for (DSimpleListItem* item : m_themeBar->items) {
(static_cast<ThemeItem*>(item))->setFrameColor(frameSelectedColor, frameNormalColor);
}
m_themeBar->themeView->repaint();

m_settings->settings->option("base.theme.default")->setValue(name);
m_themeName = name;
}

void Window::dragEnterEvent(QDragEnterEvent *event)
19 changes: 9 additions & 10 deletions editor/src/window.h
Original file line number Diff line number Diff line change
@@ -156,11 +156,19 @@ public slots:

void loadTheme(const QString &themeName);

private:
void removeActiveBlankTab(bool needSaveBefore=false);
void removeActiveReadonlyTab();
void showNewEditor(Editor *editor);
void showNotify(QString message);
DDialog* createSaveFileDialog(QString title, QString content);
int getBlankFileIndex();

private:
DBusDaemon::dbus *autoSaveDBus;

FindBar *m_findBar;
JumpLineBar *jumpLineBar;
JumpLineBar *m_jumpLineBar;
QMap<QString, Editor*> m_editorMap;
QStackedLayout *m_editorLayout;
QString m_blankFileDir;
@@ -195,15 +203,6 @@ public slots:

bool m_windowShowFlag = false;

void removeActiveBlankTab(bool needSaveBefore=false);
void removeActiveReadonlyTab();

void showNewEditor(Editor *editor);
void showNotify(QString message);

DDialog* createSaveFileDialog(QString title, QString content);

int getBlankFileIndex();

QSqlDatabase m_wordsDB;

0 comments on commit c55c5e4

Please sign in to comment.