Merge branch '0914-new' into 'dbus-interface'
Feature:Add Ui details & fit theme. See merge request kylin-desktop/kylin-nm!254
This commit is contained in:
commit
444d87029b
|
@ -43,7 +43,7 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *paren
|
|||
LanListItem::LanListItem(QWidget *parent) : ListItem(parent)
|
||||
{
|
||||
m_isActive = false;
|
||||
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-none-symbolic"));
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-none-symbolic"));
|
||||
const QString str="Not connected";
|
||||
m_nameLabel->setText(str);
|
||||
this->m_infoButton->hide();
|
||||
|
|
|
@ -8,11 +8,14 @@
|
|||
#define FRAME_WIDTH 395
|
||||
#define INFO_ICON_WIDTH 16
|
||||
#define INFO_ICON_HEIGHT 16
|
||||
#define LIGHT_HOVER_COLOR QColor(240,240,240,255)
|
||||
#define DARK_HOVER_COLOR QColor(15,15,15,255)
|
||||
|
||||
ListItem::ListItem(QWidget *parent) : QFrame(parent)
|
||||
{
|
||||
initUI();
|
||||
initConnection();
|
||||
connect(qApp, &QApplication::paletteChanged, this, &ListItem::onPaletteChanged);
|
||||
// m_itemFrame->installEventFilter(this);
|
||||
}
|
||||
|
||||
|
@ -65,6 +68,37 @@ void ListItem::mousePressEvent(QMouseEvent *event)
|
|||
return QFrame::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ListItem::enterEvent(QEvent *event)
|
||||
{
|
||||
QPalette pal = qApp->palette();
|
||||
QColor baseColor = qApp->palette().base().color();
|
||||
if (baseColor.red() > MIDDLE_COLOR) {
|
||||
pal.setColor(QPalette::Window, LIGHT_HOVER_COLOR);
|
||||
} else {
|
||||
pal.setColor(QPalette::Window, DARK_HOVER_COLOR);
|
||||
}
|
||||
this->setPalette(pal);
|
||||
return QFrame::enterEvent(event);
|
||||
}
|
||||
|
||||
void ListItem::leaveEvent(QEvent *event)
|
||||
{
|
||||
QPalette pal = qApp->palette();
|
||||
pal.setColor(QPalette::Window, qApp->palette().base().color());
|
||||
this->setPalette(pal);
|
||||
return QFrame::leaveEvent(event);
|
||||
}
|
||||
|
||||
void ListItem::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing); //反锯齿
|
||||
painter.setBrush(this->palette().brush(QPalette::Window));
|
||||
painter.setPen(Qt::transparent);
|
||||
painter.drawRoundedRect(this->rect(), 8, 8);
|
||||
return QFrame::paintEvent(event);
|
||||
}
|
||||
|
||||
//bool ListItem::eventFilter(QObject *watched, QEvent *event)
|
||||
//{
|
||||
// if (watched == m_itemFrame) {
|
||||
|
@ -100,11 +134,24 @@ void ListItem::initUI()
|
|||
m_hItemLayout->addWidget(m_infoButton);
|
||||
|
||||
m_mainLayout->addWidget(m_itemFrame);
|
||||
|
||||
this->setAutoFillBackground(true);
|
||||
this->setBackgroundRole(QPalette::Base);
|
||||
QPalette pal = qApp->palette();
|
||||
pal.setColor(QPalette::Window, qApp->palette().base().color());
|
||||
this->setPalette(pal);
|
||||
}
|
||||
|
||||
|
||||
void ListItem::initConnection()
|
||||
{
|
||||
connect(this->m_netButton, &RadioItemButton::clicked, this, &ListItem::onNetButtonClicked);
|
||||
// connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked);
|
||||
// connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked);
|
||||
}
|
||||
|
||||
void ListItem::onPaletteChanged()
|
||||
{
|
||||
QPalette pal = qApp->palette();
|
||||
pal.setColor(QPalette::Window, qApp->palette().base().color());
|
||||
this->setPalette(pal);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ public:
|
|||
protected:
|
||||
// bool eventFilter(QObject *watched, QEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
virtual void onRightButtonClicked() = 0;
|
||||
|
||||
protected:
|
||||
|
@ -42,6 +45,7 @@ private:
|
|||
|
||||
public slots:
|
||||
virtual void onNetButtonClicked() = 0;
|
||||
void onPaletteChanged();
|
||||
};
|
||||
|
||||
#endif // LISTITEM_H
|
||||
|
|
|
@ -57,6 +57,11 @@ void WlanListItem::setExpanded(const bool &expanded)
|
|||
m_pwdFrame->setVisible(expanded);
|
||||
m_autoConnectFrame->setVisible(expanded);
|
||||
emit this->itemHeightChanged(m_data->m_NetSsid);
|
||||
if (!expanded) {
|
||||
QPalette pal = qApp->palette();
|
||||
pal.setColor(QPalette::Window, qApp->palette().base().color());
|
||||
this->setPalette(pal);
|
||||
}
|
||||
}
|
||||
|
||||
void WlanListItem::resizeEvent(QResizeEvent *event)
|
||||
|
@ -88,6 +93,23 @@ void WlanListItem::onRightButtonClicked()
|
|||
m_menu->show();
|
||||
}
|
||||
|
||||
void WlanListItem::enterEvent(QEvent *event)
|
||||
{
|
||||
if (m_data) {
|
||||
return ListItem::enterEvent(event);
|
||||
} else {
|
||||
return QFrame::enterEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void WlanListItem::leaveEvent(QEvent *event)
|
||||
{
|
||||
if (m_pwdFrame && m_pwdFrame->isVisible()) {
|
||||
return QFrame::leaveEvent(event);
|
||||
}
|
||||
return ListItem::leaveEvent(event);
|
||||
}
|
||||
|
||||
void WlanListItem::initWlanUI()
|
||||
{
|
||||
m_hasPwd = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true;
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void onRightButtonClicked();
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
|
||||
signals:
|
||||
void itemHeightChanged(const QString &ssid);
|
||||
|
|
|
@ -266,10 +266,12 @@ void MainWindow::resetWindowTheme()
|
|||
if(currentTheme == "ukui-dark" || currentTheme == "ukui-black"){
|
||||
app->setStyle(new CustomStyle("ukui-dark"));
|
||||
qDebug() << "Has set color theme to ukui-dark." << Q_FUNC_INFO << __LINE__;
|
||||
emit qApp->paletteChanged(qApp->palette());
|
||||
return;
|
||||
}
|
||||
app->setStyle(new CustomStyle("ukui-light"));
|
||||
qDebug() << "Has set color theme to ukui-light." << Q_FUNC_INFO << __LINE__;
|
||||
emit qApp->paletteChanged(qApp->palette());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ void WlanPage::initWlanUI()
|
|||
m_hiddenWlanLabel->setText(tr("More..."));
|
||||
m_hiddenWlanLabel->setContentsMargins(MORE_TEXT_MARGINS);
|
||||
m_hiddenWlanLabel->installEventFilter(this);
|
||||
m_hiddenWlanLabel->setCursor(Qt::PointingHandCursor);
|
||||
m_hiddenWlanLayout->addWidget(m_hiddenWlanLabel);
|
||||
m_hiddenWlanLayout->addStretch();
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "infobutton.h"
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
#define BUTTON_SIZE 36,36
|
||||
#define ICON_SIZE 16,16
|
||||
#define BACKGROUND_COLOR QColor(0,0,0,0)
|
||||
#define FOREGROUND_COLOR_NORMAL QColor(0,0,0,255)
|
||||
#define FOREGROUND_COLOR_NORMAL qApp->palette().text().color()
|
||||
#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255)
|
||||
#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255)
|
||||
#define OUTER_PATH 8,8,16,16
|
||||
|
@ -18,6 +19,7 @@ InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
|
|||
{
|
||||
this->setFixedSize(BUTTON_SIZE);
|
||||
initUI();
|
||||
connect(qApp, &QApplication::paletteChanged, this, &InfoButton::onPaletteChanged);
|
||||
}
|
||||
|
||||
void InfoButton::initUI()
|
||||
|
@ -27,6 +29,12 @@ void InfoButton::initUI()
|
|||
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
|
||||
}
|
||||
|
||||
void InfoButton::onPaletteChanged()
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void InfoButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
|
|
|
@ -23,6 +23,9 @@ private:
|
|||
private:
|
||||
QColor m_backgroundColor;
|
||||
QColor m_foregroundColor;
|
||||
|
||||
private slots:
|
||||
void onPaletteChanged();
|
||||
};
|
||||
|
||||
#endif // INFOBUTTON_H
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "radioitembutton.h"
|
||||
#include <QPainter>
|
||||
#include <QSvgRenderer>
|
||||
#include <QApplication>
|
||||
#include <QStyle>
|
||||
#include <QDebug>
|
||||
#define FLASH_SPEED 100
|
||||
|
@ -7,8 +9,10 @@
|
|||
#define BUTTON_SIZE 36,36
|
||||
#define ICON_SIZE 16,16
|
||||
#define BACKGROUND_COLOR QColor(0,0,0,0)
|
||||
#define FOREGROUND_COLOR_NORMAL_INACTIVE QColor(230,230,230,255)
|
||||
#define FOREGROUND_COLOR_PRESS_INACTIVE QColor(217,217,217,255)
|
||||
#define FOREGROUND_COLOR_NORMAL_INACTIVE_LIGHT QColor(230,230,230,255)
|
||||
#define FOREGROUND_COLOR_NORMAL_INACTIVE_DARK QColor(55,55,55,255)
|
||||
#define FOREGROUND_COLOR_PRESS_INACTIVE_LIGHT QColor(217,217,217,255)
|
||||
#define FOREGROUND_COLOR_PRESS_INACTIVE_DARK QColor(70,70,70,255)
|
||||
#define FOREGROUND_COLOR_NORMAL_ACTIVE QColor(55,144,250,255)
|
||||
#define FOREGROUND_COLOR_PRESS_ACTIVE QColor(36,109,212,255)
|
||||
|
||||
|
@ -26,6 +30,7 @@ RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
|
|||
//JXJ_TODO loading动画
|
||||
connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted);
|
||||
connect(this , &RadioItemButton::requestStopLoading, this, &RadioItemButton::onLoadingStopped);
|
||||
connect(qApp, &QApplication::paletteChanged, this, &RadioItemButton::onPaletteChanged);
|
||||
}
|
||||
|
||||
void RadioItemButton::startLoading()
|
||||
|
@ -43,13 +48,27 @@ void RadioItemButton::setButtonIcon(const QIcon &icon)
|
|||
if (icon.isNull()) {
|
||||
return;
|
||||
}
|
||||
m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE));
|
||||
m_pixmap = icon.pixmap(ICON_SIZE);
|
||||
m_iconLabel->setPixmap(m_pixmap);
|
||||
}
|
||||
|
||||
void RadioItemButton::setActive(const bool &isActive)
|
||||
{
|
||||
m_isActivated = isActive;
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
|
||||
// m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
|
||||
if (m_isActivated) {
|
||||
m_backgroundColor = FOREGROUND_COLOR_NORMAL_ACTIVE;
|
||||
// m_iconLabel->setProperty("useIconHighlightEffect", 0x08);
|
||||
m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE));
|
||||
} else {
|
||||
if (qApp->palette().base().color().red() > MIDDLE_COLOR) {
|
||||
m_backgroundColor = FOREGROUND_COLOR_NORMAL_INACTIVE_LIGHT;
|
||||
m_iconLabel->setPixmap(m_pixmap);
|
||||
} else {
|
||||
m_backgroundColor = FOREGROUND_COLOR_NORMAL_INACTIVE_DARK;
|
||||
m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE));
|
||||
}
|
||||
}
|
||||
}
|
||||
void RadioItemButton::onLoadingStarted()
|
||||
{
|
||||
|
@ -99,6 +118,17 @@ void RadioItemButton::onLoadingTimerTimeout()
|
|||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onPaletteChanged()
|
||||
{
|
||||
if (qApp->palette().base().color().red() > MIDDLE_COLOR) {
|
||||
m_backgroundColor = FOREGROUND_COLOR_NORMAL_INACTIVE_LIGHT;
|
||||
m_iconLabel->setPixmap(m_pixmap);
|
||||
} else {
|
||||
m_backgroundColor = FOREGROUND_COLOR_NORMAL_INACTIVE_DARK;
|
||||
m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE));
|
||||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
|
@ -124,14 +154,62 @@ void RadioItemButton::paintEvent(QPaintEvent *event)
|
|||
|
||||
void RadioItemButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_PRESS_ACTIVE : FOREGROUND_COLOR_PRESS_INACTIVE;
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_PRESS_ACTIVE :
|
||||
(qApp->palette().base().color().red() > MIDDLE_COLOR ?
|
||||
FOREGROUND_COLOR_PRESS_INACTIVE_LIGHT :
|
||||
FOREGROUND_COLOR_PRESS_INACTIVE_DARK);
|
||||
this->repaint();
|
||||
return QPushButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void RadioItemButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE :
|
||||
(qApp->palette().base().color().red() > MIDDLE_COLOR ?
|
||||
FOREGROUND_COLOR_NORMAL_INACTIVE_LIGHT :
|
||||
FOREGROUND_COLOR_NORMAL_INACTIVE_DARK);
|
||||
this->repaint();
|
||||
return QPushButton::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
const QPixmap RadioItemButton::loadSvg(const QPixmap &source, const PixmapColor &cgColor)
|
||||
{
|
||||
QImage img = source.toImage();
|
||||
for (int x = 0; x < img.width(); x++) {
|
||||
for (int y = 0; y < img.height(); y++) {
|
||||
auto color = img.pixelColor(x, y);
|
||||
if (color.alpha() > 0) {
|
||||
switch (cgColor) {
|
||||
case PixmapColor::WHITE:
|
||||
color.setRed(255);
|
||||
color.setGreen(255);
|
||||
color.setBlue(255);
|
||||
img.setPixelColor(x, y, color);
|
||||
break;
|
||||
case PixmapColor::BLACK:
|
||||
color.setRed(0);
|
||||
color.setGreen(0);
|
||||
color.setBlue(0);
|
||||
img.setPixelColor(x, y, color);
|
||||
break;
|
||||
case PixmapColor::GRAY:
|
||||
color.setRed(152);
|
||||
color.setGreen(163);
|
||||
color.setBlue(164);
|
||||
img.setPixelColor(x, y, color);
|
||||
break;
|
||||
case PixmapColor::BLUE:
|
||||
color.setRed(61);
|
||||
color.setGreen(107);
|
||||
color.setBlue(229);
|
||||
img.setPixelColor(x, y, color);
|
||||
break;
|
||||
default:
|
||||
return source;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return QPixmap::fromImage(img);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QLabel>
|
||||
#include<QTimer>
|
||||
|
||||
#define MIDDLE_COLOR 178
|
||||
|
||||
class RadioItemButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -15,6 +17,13 @@ public:
|
|||
void stopLoading();
|
||||
void setButtonIcon(const QIcon &icon);
|
||||
void setActive(const bool &isActive);
|
||||
enum PixmapColor {
|
||||
WHITE = 0,
|
||||
BLACK,
|
||||
GRAY,
|
||||
BLUE,
|
||||
};
|
||||
const QPixmap loadSvg(const QPixmap &source, const PixmapColor &color);
|
||||
|
||||
signals:
|
||||
void requestStartLoading();
|
||||
|
@ -33,11 +42,13 @@ private:
|
|||
QColor m_backgroundColor;
|
||||
|
||||
int currentPage = 8;
|
||||
QPixmap m_pixmap;
|
||||
|
||||
private slots:
|
||||
void onLoadingStarted();
|
||||
void onLoadingStopped();
|
||||
void onLoadingTimerTimeout();
|
||||
void onPaletteChanged();
|
||||
};
|
||||
|
||||
#endif // NETBUTTON_H
|
||||
|
|
Loading…
Reference in New Issue