File indexing completed on 2024-12-08 10:56:46
0001 /* 0002 SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "layoutstableview.h" 0007 0008 //! Qt 0009 #include <QDebug> 0010 #include <QMimeData> 0011 0012 //! KDE 0013 #include <KLocalizedString> 0014 0015 #define MARGIN 15 0016 0017 namespace Latte { 0018 namespace Settings { 0019 namespace View { 0020 0021 LayoutsTableView::LayoutsTableView(QWidget *parent) 0022 : QTableView(parent) 0023 { 0024 setAcceptDrops(true); 0025 0026 m_overlayDropMessage = new QLabel(this); 0027 m_overlayDropMessage->setAcceptDrops(true); 0028 m_overlayDropMessage->setVisible(false); 0029 m_overlayDropMessage->setText(i18n("Drop layout files here...")); 0030 0031 m_overlayDropMessage->setAutoFillBackground(true); 0032 QFont fn = m_overlayDropMessage->font(); 0033 fn.setBold(true); 0034 fn.setPointSize(fn.pointSize() * 3); 0035 m_overlayDropMessage->setFont(fn); 0036 m_overlayDropMessage->setAlignment(Qt::AlignCenter); 0037 0038 QPalette palette = m_overlayDropMessage->palette(); 0039 QColor backgroundColor = palette.color(QPalette::Background); 0040 QColor foregroundColor = palette.color(QPalette::Foreground); 0041 0042 QColor borderColor = foregroundColor; 0043 borderColor.setAlphaF(0.5); 0044 backgroundColor.setAlphaF(0.8); 0045 foregroundColor.setAlphaF(0.5); 0046 0047 qDebug() << borderColor.name() << " _ " << backgroundColor.name(); 0048 0049 QString css = "QLabel{border: 1px solid "+borderColor.name(QColor::HexArgb)+"; border-radius: 15px;"; 0050 css += "background:"+backgroundColor.name(QColor::HexArgb)+"; color:" +foregroundColor.name(QColor::HexArgb)+ ";}"; 0051 0052 m_overlayDropMessage->setStyleSheet(css); 0053 } 0054 0055 void LayoutsTableView::paintEvent(QPaintEvent *event) 0056 { 0057 QTableView::paintEvent(event); 0058 } 0059 0060 void LayoutsTableView::dragEntered(QDragEnterEvent *event) 0061 { 0062 m_overlayDropMessage->move(MARGIN, MARGIN); 0063 m_overlayDropMessage->resize(width() - 2*MARGIN, height() - 2*MARGIN); 0064 0065 m_overlayDropMessage->raise(); 0066 if (event->mimeData()->hasUrls()) { 0067 m_overlayDropMessage->setText(i18n("Drop layout files here...")); 0068 } else if(event->mimeData()->hasText()) { 0069 m_overlayDropMessage->setText(i18n("Drop raw layout text here...")); 0070 } else { 0071 m_overlayDropMessage->setText(i18n("Unsupported data!")); 0072 } 0073 m_overlayDropMessage->setVisible(true); 0074 } 0075 0076 void LayoutsTableView::dragLeft() 0077 { 0078 m_overlayDropMessage->setVisible(false); 0079 } 0080 0081 } 0082 } 0083 } 0084