Merge branch '0330-dev' into 'main'

Fix:Fit ukui-kwin for setting widget.

See merge request kylin-desktop/ukui-search!2
This commit is contained in:
PengfeiZhang 2021-03-30 09:17:24 +00:00
commit af643ec4ad
5 changed files with 79 additions and 34 deletions

View File

@ -244,7 +244,8 @@ int main(int argc, char *argv[])
MainWindow *w = new MainWindow; MainWindow *w = new MainWindow;
QStringList arguments = QCoreApplication::arguments(); QStringList arguments = QCoreApplication::arguments();
// centerToScreen(w); // centerToScreen(w);
w->moveToPanel(); // w->moveToPanel();
centerToScreen(w);
//使用窗管的无边框策略 //使用窗管的无边框策略
// w->setProperty("useStyleWindowManager", false); //禁用拖动 // w->setProperty("useStyleWindowManager", false); //禁用拖动
@ -257,7 +258,8 @@ int main(int argc, char *argv[])
app.setActivationWindow(w); app.setActivationWindow(w);
if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) { if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) {
w->moveToPanel(); // w->moveToPanel();
centerToScreen(w);
XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints); XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints);
w->show(); w->show();
} }

View File

@ -75,7 +75,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->setWindowTitle(tr("ukui-search")); this->setWindowTitle(tr("ukui-search"));
initUi(); initUi();
setProperty("useStyleWindowManager", false); // setProperty("useStyleWindowManager", false); //禁止拖动
m_hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; m_hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
m_hints.functions = MWM_FUNC_ALL; m_hints.functions = MWM_FUNC_ALL;
m_hints.decorations = MWM_DECOR_BORDER; m_hints.decorations = MWM_DECOR_BORDER;
@ -136,7 +136,8 @@ MainWindow::MainWindow(QWidget *parent) :
{ {
if (!this->isVisible()) { if (!this->isVisible()) {
clearSearchResult(); clearSearchResult();
this->moveToPanel(); // this->moveToPanel();
centerToScreen(this);
XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints); XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
this->show(); this->show();
this->m_searchLayout->focusIn(); //打开主界面时输入框夺焦,可直接输入 this->m_searchLayout->focusIn(); //打开主界面时输入框夺焦,可直接输入
@ -202,10 +203,14 @@ void MainWindow::initUi()
m_menuBtn->setFlat(true); m_menuBtn->setFlat(true);
connect(m_menuBtn, &QPushButton::clicked, this, [ = ]() { connect(m_menuBtn, &QPushButton::clicked, this, [ = ]() {
if (m_settingsWidget) { //当此窗口已存在时,仅需置顶 if (m_settingsWidget) { //当此窗口已存在时,仅需置顶
if (!m_settingsWidget->isVisible()) {
centerToScreen(m_settingsWidget);
}
m_settingsWidget->showWidget(); m_settingsWidget->showWidget();
return; return;
} }
m_settingsWidget = new SettingsWidget(); m_settingsWidget = new SettingsWidget();
centerToScreen(m_settingsWidget);
m_settingsWidget->show(); m_settingsWidget->show();
connect(m_settingsWidget, &SettingsWidget::settingWidgetClosed, this, [ = ]() { connect(m_settingsWidget, &SettingsWidget::settingWidgetClosed, this, [ = ]() {
QTimer::singleShot(100, this, [ = ] { QTimer::singleShot(100, this, [ = ] {
@ -273,7 +278,8 @@ void MainWindow::bootOptionsFilter(QString opt)
{ {
if (opt == "-s" || opt == "--show") { if (opt == "-s" || opt == "--show") {
clearSearchResult(); clearSearchResult();
this->moveToPanel(); // this->moveToPanel();
centerToScreen(this);
XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints); XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
this->show(); this->show();
this->m_searchLayout->focusIn(); this->m_searchLayout->focusIn();
@ -391,6 +397,32 @@ void MainWindow::moveToPanel()
} }
} }
/**
* @brief MainWindow::centerToScreen 使
* @param widget
*/
void MainWindow::centerToScreen(QWidget* widget) {
if (!widget)
return;
QDesktopWidget* m = QApplication::desktop();
QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
int desk_x = desk_rect.width();
int desk_y = desk_rect.height();
int x = widget->width();
int y = widget->height();
QDBusInterface primaryScreenInterface("org.ukui.SettingsDaemon",
"/org/ukui/SettingsDaemon/wayland",
"org.ukui.SettingsDaemon.wayland",
QDBusConnection::sessionBus());
if (QDBusReply<int>(primaryScreenInterface.call("x")).isValid()) {
QDBusReply<int> width = primaryScreenInterface.call("width");
QDBusReply<int> height = primaryScreenInterface.call("height");
desk_x = width;
desk_y = height;
}
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
}
//使用GSetting获取当前窗口应该使用的透明度 //使用GSetting获取当前窗口应该使用的透明度
double MainWindow::getTransparentData() double MainWindow::getTransparentData()
{ {

View File

@ -65,6 +65,7 @@ public:
*/ */
void searchContent(QString searchcontent); void searchContent(QString searchcontent);
void moveToPanel(); void moveToPanel();
void centerToScreen(QWidget* widget);
MotifWmHints m_hints; MotifWmHints m_hints;
private: private:

View File

@ -30,12 +30,18 @@
#include "file-utils.h" #include "file-utils.h"
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
SettingsWidget::SettingsWidget(QWidget *parent) : QDialog(parent) SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
{ {
this->setWindowIcon(QIcon::fromTheme("kylin-search")); this->setWindowIcon(QIcon::fromTheme("kylin-search"));
this->setWindowTitle(tr("ukui-search-settings")); this->setWindowTitle(tr("ukui-search-settings"));
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); // this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground); // this->setAttribute(Qt::WA_TranslucentBackground);
m_hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
m_hints.functions = MWM_FUNC_ALL;
m_hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
initUi(); initUi();
refreshIndexState(); refreshIndexState();
setupBlackList(GlobalSettings::getInstance()->getBlockDirs()); setupBlackList(GlobalSettings::getInstance()->getBlockDirs());
@ -369,6 +375,7 @@ void SettingsWidget::showWidget()
flags &= ~Qt::WindowStaysOnTopHint; flags &= ~Qt::WindowStaysOnTopHint;
this->setWindowFlags(flags); this->setWindowFlags(flags);
m_timer->start(); m_timer->start();
XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
this->show(); this->show();
} }
@ -432,40 +439,39 @@ void SettingsWidget::paintEvent(QPaintEvent *event) {
QPainter p(this); QPainter p(this);
p.setRenderHint(QPainter::Antialiasing); p.setRenderHint(QPainter::Antialiasing);
QPainterPath rectPath; QPainterPath rectPath;
rectPath.addRoundedRect(this->rect().adjusted(10, 10, -10, -10), 6, 6); rectPath.addRoundedRect(this->rect(), 6, 6);
// 画一个黑底 // // 画一个黑底
QPixmap pixmap(this->rect().size()); // QPixmap pixmap(this->rect().size());
pixmap.fill(Qt::transparent); // pixmap.fill(Qt::transparent);
QPainter pixmapPainter(&pixmap); // QPainter pixmapPainter(&pixmap);
pixmapPainter.setRenderHint(QPainter::Antialiasing); // pixmapPainter.setRenderHint(QPainter::Antialiasing);
pixmapPainter.setPen(Qt::transparent); // pixmapPainter.setPen(Qt::transparent);
pixmapPainter.setBrush(Qt::black); // pixmapPainter.setBrush(Qt::black);
pixmapPainter.setOpacity(0.65); // pixmapPainter.setOpacity(0.65);
pixmapPainter.drawPath(rectPath); // pixmapPainter.drawPath(rectPath);
pixmapPainter.end(); // pixmapPainter.end();
// 模糊这个黑底 // // 模糊这个黑底
QImage img = pixmap.toImage(); // QImage img = pixmap.toImage();
qt_blurImage(img, 10, false, false); // qt_blurImage(img, 10, false, false);
// 挖掉中心 // // 挖掉中心
pixmap = QPixmap::fromImage(img); // pixmap = QPixmap::fromImage(img);
QPainter pixmapPainter2(&pixmap); // QPainter pixmapPainter2(&pixmap);
pixmapPainter2.setRenderHint(QPainter::Antialiasing); // pixmapPainter2.setRenderHint(QPainter::Antialiasing);
pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear); // pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear);
pixmapPainter2.setPen(Qt::transparent); // pixmapPainter2.setPen(Qt::transparent);
pixmapPainter2.setBrush(Qt::transparent); // pixmapPainter2.setBrush(Qt::transparent);
pixmapPainter2.drawPath(rectPath); // pixmapPainter2.drawPath(rectPath);
// 绘制阴影 // // 绘制阴影
p.drawPixmap(this->rect(), pixmap, pixmap.rect()); // p.drawPixmap(this->rect(), pixmap, pixmap.rect());
// 绘制一个背景 // 绘制一个背景
p.save(); p.save();
p.fillPath(rectPath,palette().color(QPalette::Base)); p.fillPath(rectPath,palette().color(QPalette::Base));
p.restore(); p.restore();
} }
/** /**

View File

@ -33,8 +33,9 @@
#include <QScrollArea> #include <QScrollArea>
#include <QTimer> #include <QTimer>
#include <libsearch.h> #include <libsearch.h>
#include "xatom-helper.h"
class SettingsWidget : public QDialog class SettingsWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -54,6 +55,9 @@ private:
void resize(); void resize();
void showWarningDialog(const int&); void showWarningDialog(const int&);
void resetWebEngine(); void resetWebEngine();
MotifWmHints m_hints;
//标题栏 //标题栏
QVBoxLayout * m_mainLyt = nullptr; QVBoxLayout * m_mainLyt = nullptr;
QFrame * m_contentFrame = nullptr; QFrame * m_contentFrame = nullptr;