123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #include "QInfoListWidget.h"
- #include "BootGlobal.h"
- #include <QScrollBar>
- //static const QColor g_sLeftBackgroundColor = QColor(101, 105, 108, 255); //#65696C
- //static const QColor g_sRightBackgroundColor = QColor(161, 163, 165, 255); //#A1A3A5
- namespace {
- int ColorDodge(int primaryColor, int secondaryColors)
- {
- if(secondaryColors >= 255) {
- return 255;
- }
- //基色 +(基色 * 混合色)/(255 - 混合色)= 结果色
- int result = (primaryColor + (uint)(primaryColor * secondaryColors) / (255 - secondaryColors));
- if(result > 255) {
- result = 255;
- } else if(result < 0) {
- result = 0;
- }
- return result;
- }
- QColor GetSortedDisplayColor(const QListWidget* parent)
- {
- const int stepMax = 100;
- const int currItemsCount = parent->count();
- const int j = (stepMax - currItemsCount % stepMax);
- const int gradientR = ColorDodge(205, j);
- const int gradientG = ColorDodge(38, j);
- const int gradientB = ColorDodge(38, j);
- return QColor(gradientR, gradientG, gradientB, 255);
- }
- }
- QBaseListWidgetItem::QBaseListWidgetItem(const QString &text, InfoType it, LevelType lt)
- :QListWidgetItem(text),infoType(it),levelType(lt)
- {
- setFlags(Qt::ItemIsEnabled | Qt::NoItemFlags);
- }
- void QBaseListWidgetItem::AppentToWidget(QInfoListWidget* container, bool insertFront)
- {
- if(insertFront)
- {
- container->insertItem(0, this);
- container->setCurrentRow(0);
- } else {
- container->addItem(this);
- container->setCurrentRow(container->count()-1);
- }
- setForeground(FrontColor());
- setBackground(BackgroundColor());
- QFont font;
- font.setFamily(QStringLiteral("微软雅黑"));
- font.setPointSize(10);
- this->setFont(font);
- if(insertFront) {
- container->RemoveDuplicateItem();
- }
- }
- QColor QBaseListWidgetItem::FrontColor() const
- {
- auto colorValue = Qt::black;
- return QColor(Qt::GlobalColor(colorValue));
- }
- QColor QBaseListWidgetItem::BackgroundColor() const
- {
- return GetLeftBackgoundColor();
- }
- QInfoListWidgetItem::QInfoListWidgetItem(const QString &text, LevelType lt)
- :QBaseListWidgetItem(text, Info, lt)
- {
- }
- QColor QWarnListWidgetItem::FrontColor() const
- {
- auto colorValue = Qt::white;
- return QColor(colorValue);
- }
- QColor QLightWarnListWidgetItem::FrontColor() const
- {
- auto colorValue = Qt::yellow;
- return QColor(colorValue);
- }
- QColor QLightWarnListWidgetItem::BackgroundColor() const
- {
- auto colorValue = Qt::black;
- return QColor(colorValue);
- }
- QColor QErrorListWidgetItem::FrontColor() const
- {
- auto colorValue = Qt::darkRed;
- return QColor(colorValue);
- }
- QColor QLightErrorListWidgetItem::FrontColor() const
- {
- auto colorValue = Qt::red;
- return QColor(colorValue);
- }
- QColor QLightErrorListWidgetItem::BackgroundColor() const
- {
- auto colorValue = Qt::black;
- return QColor(colorValue);
- }
- QColor QTipErrorListWidgetItem::FrontColor() const
- {
- auto colorValue = Qt::red;
- return QColor(colorValue);
- }
- QColor QTipErrorListWidgetItem::BackgroundColor() const
- {
- return QColor(245, 245, 245, 255);
- }
- QColor QTipListWidgetItem::FrontColor() const
- {
- QListWidget* parent = listWidget();
- if(parent != nullptr)
- return GetSortedDisplayColor(parent);
- auto colorValue = Qt::darkRed;
- return QColor(colorValue);
- }
- QColor QTipListWidgetItem::BackgroundColor() const
- {
- return GetRightBackgoundColor();
- }
- QColor QConsoleListWidgetItem::FrontColor() const
- {
- return GetConsoleFrontColor();
- }
- QColor QConsoleListWidgetItem::BackgroundColor() const
- {
- auto colorValue = Qt::black;
- return QColor(colorValue);
- }
- QInfoListWidget::QInfoListWidget(QWidget* parent)
- :QListWidget(parent)
- {
- Init();
- }
- void QInfoListWidget::Init()
- {
- this->setViewMode(QListView::ListMode);
- this->setFlow(QListView::TopToBottom);
- this->setSortingEnabled(false);
- // Hide the scrollbar
- this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- /*disable hightlight when cursor hover*/
- this->setStyleSheet("QListWidget::item:hover{background: transparent;}");
- /*hide border*/
- this->setFrameShape(QListWidget::NoFrame);
- }
- void QInfoListWidget::WheelEvent(QWheelEvent* event)
- {
- int degress = event->angleDelta().ry() * 0.5;
- if(event->orientation() == Qt::Vertical)
- verticalScrollBar()->setValue(verticalScrollBar()->value() - degress);
- event->accept();
- }
- void QLeftInfoListWidget::PostInit()
- {
- qDebug("QLeftInfoListWidget::PostInit()");
- this->setStyleSheet("QListWidget{background: #65696C;outline:0px;}"
- "QListWidget::item{padding-top:1px; padding-bottom:1px;}"
- "QListWidget::item:hover{background: #65696C;}");
- }
- void QRightInfoListWidget::PostInit()
- {
- qDebug("QRightInfoListWidget::PostInit()");
- //SetWidgetBackgroundColor(this, GetRightBackgoundColor());
- this->setStyleSheet("QListWidget{background: #A1A3A5;outline:0px;}" //去除选中时的虚线
- "QListWidget::item:selected,QListWidget::item:hover{background: #A1A3A5;}");
- }
|