void SwitchMonitor::initScreenMode()
{
    // for each mode, we would do the same operations to change it's style when app starts
    switch (displaymode) {
    case Custom:
        //        m_CurrentIndexOfMonitorItem = -1;
        break;
    case Duplicate:
        showThemeImage(getThemeIconPath("project_screen-duplicate-symbolic-focus"), m_DuplicateScreenImageSvg, m_DuplicateScreenImageLabel);
        m_DuplicateScreenText->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
        m_CurrentIndexOfMonitorItem = 0;
        break;
    case Expanded:
        showThemeImage(getThemeIconPath("project_screen-extend-symbolic-focus"), m_ExpandedScreenImageSvg, m_ExpandedScreenImageLabel);
        m_ExpandedScreenText->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
        m_CurrentIndexOfMonitorItem = 1;
        break;
    case OneScreen:
        QString primaryScreenName = m_DisplayInterface->primary();
        for (int i = 0, length = m_ScreenList.length(); i < length; i++) {
            if (m_ScreenList[i] == primaryScreenName) {
                showThemeImage(getThemeIconPath("project_screen-onlyone-symbolic-focus"), m_ImageSvgList[i], m_ImageLabelList[i]);
                m_TextLabelList[i]->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
                // m_CurrentIndexOfMonitorItem is always 2 bigger than m_ScreenList's i
                m_CurrentIndexOfMonitorItem = i + 2;
            }
        }
        break;
    }
}
void SwitchMonitor::initExtendMode(){
    // for expanded mode
    QWidget *expandedScreenItem = new QWidget(m_MonitersWrapper);
    QVBoxLayout *vLayoutOfExpandedScreen = new QVBoxLayout(expandedScreenItem);
    // image label for expanded mode
    m_ExpandedScreenImageSvg = new QSvgWidget(expandedScreenItem);
    m_ExpandedScreenImageSvg->setFixedSize(IMAGE_SIZE, IMAGE_SIZE);
    m_ExpandedScreenImageLabel = new QLabel(expandedScreenItem);
    m_ExpandedScreenImageLabel->setFixedSize(IMAGE_SIZE, IMAGE_SIZE);
    showThemeImage(getThemeIconPath("project_screen-extend-symbolic"), m_ExpandedScreenImageSvg, m_ExpandedScreenImageLabel);
    // text label for expanded mode
    m_ExpandedScreenText = new QLabel(expandedScreenItem);
    m_ExpandedScreenText->setText(tr("Extend"));
    m_ExpandedScreenText->setAlignment(Qt::AlignCenter);
    m_ExpandedScreenText->setStyleSheet(MONITOR_TEXT_NORMAL_STYLE);
    // add above 2 widgets
    if(getThemeIconPath("project_screen-extend-symbolic").endsWith(".svg")){
        vLayoutOfExpandedScreen->addWidget(m_ExpandedScreenImageSvg, 0, Qt::AlignHCenter);
    }else{
        vLayoutOfExpandedScreen->addWidget(m_ExpandedScreenImageLabel, 0, Qt::AlignHCenter);
    }
    vLayoutOfExpandedScreen->addWidget(m_ExpandedScreenText, 0, Qt::AlignHCenter);

    m_HBoxLayout->addWidget(expandedScreenItem);
}
void SwitchMonitor::initOneScreenMode(){
    // for one-screen mode
    for (int i = 0, length = m_ScreenList.length(); i < length; i++) {
        // one-screen mode item
        QWidget *item = new QWidget(m_MonitersWrapper);
        QVBoxLayout *vLayout = new QVBoxLayout(item);
        // image label for one-screen mode
        QSvgWidget *imageSvg = new QSvgWidget(item);
        imageSvg->setFixedSize(IMAGE_SIZE, IMAGE_SIZE);
        QLabel* imageLabel = new QLabel(item);
        imageLabel->setFixedSize(IMAGE_SIZE, IMAGE_SIZE);
        showThemeImage(getThemeIconPath("project_screen-onlyone-symbolic"), imageSvg, imageLabel);
        // text label for one-screen mode
        QLabel *textLabel = new QLabel(item);
        textLabel->setText(m_ScreenList[i]);
        textLabel->setAlignment(Qt::AlignCenter);
        textLabel->setStyleSheet(MONITOR_TEXT_NORMAL_STYLE);
        // store imagelabel and textlabel into lists, so that we can change their style later
        m_ImageSvgList << imageSvg;
        m_ImageLabelList << imageLabel;
        m_TextLabelList << textLabel;
        // add above 2 widgets
        if(getThemeIconPath("project_screen-onlyone-symbolic").endsWith(".svg")){
            vLayout->addWidget(imageSvg, 0, Qt::AlignHCenter);
        }else{
            vLayout->addWidget(imageLabel, 0, Qt::AlignHCenter);
        }
        vLayout->addWidget(textLabel, 0, Qt::AlignHCenter);

        m_HBoxLayout->addWidget(item);
    }
}
Beispiel #4
0
void DockAppIcon::setIcon(const QString &iconPath)
{
    m_iconPath = iconPath;

    QPixmap pixmap(48, 48);

    // iconPath is an absolute path of the system.
    if (QFile::exists(iconPath)) {
        pixmap = QPixmap(iconPath);
    } else if (iconPath.startsWith("data:image/")) {
        // iconPath is a string representing an inline image.
        QStringList strs = iconPath.split("base64,");
        if (strs.length() == 2) {
            QByteArray data = QByteArray::fromBase64(strs.at(1).toLatin1());
            pixmap.loadFromData(data);
        }
    } else {
        // try to read the iconPath as a icon name.
        QString path = getThemeIconPath(iconPath);
        if (path.isEmpty())
            path = getThemeIconPath("application-x-desktop");
        if (path.endsWith(".svg")) {
            QSvgRenderer renderer(path);
            pixmap.fill(Qt::transparent);

            QPainter painter;
            painter.begin(&pixmap);

            renderer.render(&painter);

            painter.end();
        } else {
            pixmap.load(path);
        }
    }

    if (!pixmap.isNull()) {
        pixmap = pixmap.scaled(m_modeData->getAppIconSize(),
                               m_modeData->getAppIconSize(),
                               Qt::KeepAspectRatioByExpanding,
                               Qt::SmoothTransformation);

        setPixmap(pixmap);
    }
}
void showThemeImage(QString iconName, QSvgWidget* svgLoader, QLabel* notSvgLoader){
    if(iconName.endsWith(".svg")){
        svgLoader->load(iconName);
    }else if(iconName.isEmpty()){
        svgLoader->load(getThemeIconPath("application-default-icon"));
    }else{
        // 56 is the size of image
        notSvgLoader->setPixmap(QPixmap(iconName).scaled(56,56,Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    }
}
Beispiel #6
0
void MainItem::dropEvent(QDropEvent *event)
{
    updateIcon(false);

    if (event->source())
        return;

    if (event->mimeData()->formats().indexOf("RequestDock") != -1){    //from desktop or launcher
        QJsonObject dataObj = QJsonDocument::fromJson(event->mimeData()->data("RequestDock")).object();
        if (!dataObj.isEmpty()){
            QString appKey = dataObj.value("appKey").toString();
            QString appName = dataObj.value("appName").toString();
            if (appKey.isEmpty())
                return;
            event->ignore();

            ConfirmUninstallDialog *dialog = new ConfirmUninstallDialog;
            //TODO: need real icon name
            dialog->setIcon(getThemeIconPath(appKey));
            QString message = tr("Are you sure to uninstall %1?").arg(appName);
            dialog->setMessage(message);
            connect(dialog, &ConfirmUninstallDialog::buttonClicked, [=](int key){
                dialog->deleteLater();
                if (key == 1){
                    qWarning() << "Uninstall application:" << appKey << appName;
                    m_launcher->RequestUninstall(appKey, true);
                }
            });
            dialog->exec();
        }
    }
    else//File or Dirctory
    {
        QStringList files;
        foreach (QUrl fileUrl, event->mimeData()->urls())
            files << fileUrl.path();

        QDBusPendingReply<QString, QDBusObjectPath, QString> tmpReply = m_dfo->NewTrashJob(files, false, "", "", "");
        QDBusObjectPath op = tmpReply.argumentAt(1).value<QDBusObjectPath>();
        DBusTrashJob * dtj = new DBusTrashJob(op.path(), this);
        connect(dtj, &DBusTrashJob::Done, dtj, &DBusTrashJob::deleteLater);
        connect(dtj, &DBusTrashJob::Done, [=](){
            updateIcon(false);
        });

        if (dtj->isValid())
            dtj->Execute();

        qWarning()<< op.path() << "Move files to trash: "<< files;
    }
}
Beispiel #7
0
void MainItem::execUninstall(const QString &appKey, const QString &appName, const QString &appIcon)
{
    ConfirmUninstallDialog *dialog = new ConfirmUninstallDialog;
    //TODO: need real icon name
    dialog->setIcon(getThemeIconPath(appIcon));
    QString message = tr("Are you sure to uninstall %1?").arg(appName);
    dialog->setMessage(message);
    connect(dialog, &ConfirmUninstallDialog::buttonClicked, [=](int key){
        dialog->deleteLater();
        if (key == 1){
            qWarning() << "Uninstall application:" << appKey << appName;
            m_launcher->RequestUninstall(appKey, true);
        }
    });
    dialog->exec();
}
Beispiel #8
0
void MainItem::updateIcon(bool isOpen)
{
    QString iconName = "";
    if (isOpen)
    {
        if (m_dftm->ItemCount() > 0)
            iconName = "user-trash-full-opened";
        else
            iconName = "user-trash-empty-opened";
    }
    else
    {
        if (m_dftm->ItemCount() > 0)
            iconName = "user-trash-full";
        else
            iconName = "user-trash-empty";
    }

    QPixmap pixmap(getThemeIconPath(iconName));
    setPixmap(pixmap.scaled(Dock::APPLET_FASHION_ICON_SIZE,Dock::APPLET_FASHION_ICON_SIZE));
}
Beispiel #9
0
void MainItem::emptyTrash()
{
    ClearTrashDialog *dialog = new ClearTrashDialog;
    dialog->setIcon(getThemeIconPath("user-trash-full"));
    connect(dialog, &ClearTrashDialog::buttonClicked, [=](int key){
        dialog->deleteLater();
        if (key == 1){
            qWarning() << "Clear trash...";
            QDBusPendingReply<QString, QDBusObjectPath, QString> tmpReply = m_dfo->NewEmptyTrashJob(false, "", "", "");
            QDBusObjectPath op = tmpReply.argumentAt(1).value<QDBusObjectPath>();
            DBusEmptyTrashJob * detj = new DBusEmptyTrashJob(op.path(), this);
            connect(detj, &DBusEmptyTrashJob::Done, detj, &DBusEmptyTrashJob::deleteLater);
            connect(detj, &DBusEmptyTrashJob::Done, [=](){
                updateIcon(false);
            });

            if (detj->isValid())
                detj->Execute();
        }
    });
    dialog->exec();
}
void SwitchMonitor::reHighlightMonitor()
{
    if (m_CurrentIndexOfMonitorItem == 0) {
        showThemeImage(getThemeIconPath("project_screen-duplicate-symbolic-focus"), m_DuplicateScreenImageSvg, m_DuplicateScreenImageLabel);
        m_DuplicateScreenText->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
        showThemeImage(getThemeIconPath("project_screen-onlyone-symbolic"), m_ImageSvgList[m_ScreenList.length() - 1], m_ImageLabelList[m_ScreenList.length() - 1]);
        m_TextLabelList[m_ScreenList.length() - 1]->setStyleSheet(MONITOR_TEXT_NORMAL_STYLE);
    } else if (m_CurrentIndexOfMonitorItem == 1) {
        showThemeImage(getThemeIconPath("project_screen-extend-symbolic-focus"), m_ExpandedScreenImageSvg, m_ExpandedScreenImageLabel);
        m_ExpandedScreenText->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
        showThemeImage(getThemeIconPath("project_screen-duplicate-symbolic"), m_DuplicateScreenImageSvg, m_DuplicateScreenImageLabel);
        m_DuplicateScreenText->setStyleSheet(MONITOR_TEXT_NORMAL_STYLE);
    } else if (m_CurrentIndexOfMonitorItem == 2) {
        showThemeImage(getThemeIconPath("project_screen-onlyone-symbolic-focus"), m_ImageSvgList[0], m_ImageLabelList[0]);
        m_TextLabelList[0]->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
        showThemeImage(getThemeIconPath("project_screen-extend-symbolic"), m_ExpandedScreenImageSvg, m_ExpandedScreenImageLabel);
        m_ExpandedScreenText->setStyleSheet(MONITOR_TEXT_NORMAL_STYLE);
    } else {
        showThemeImage(getThemeIconPath("project_screen-onlyone-symbolic-focus"), m_ImageSvgList[m_CurrentIndexOfMonitorItem - 2], m_ImageLabelList[m_CurrentIndexOfMonitorItem - 2]);
        m_TextLabelList[m_CurrentIndexOfMonitorItem - 2]->setStyleSheet(MONITOR_TEXT_HIGHLIGHT_STYLE);
        showThemeImage(getThemeIconPath("project_screen-onlyone-symbolic"), m_ImageSvgList[m_CurrentIndexOfMonitorItem - 3], m_ImageLabelList[m_CurrentIndexOfMonitorItem - 3]);
        m_TextLabelList[m_CurrentIndexOfMonitorItem - 3]->setStyleSheet(MONITOR_TEXT_NORMAL_STYLE);
    }
}
QPixmap ThemeAppIcon::getIconPixmap(QString iconPath, int width, int height){
    Q_ASSERT(false);
    if (iconPath.length() == 0){
        iconPath = "application-x-desktop";
    }
    QPixmap pixmap(width, height);
    // iconPath is an absolute path of the system
    if (QFile::exists(iconPath) && iconPath.contains(QDir::separator())) {
        pixmap = QPixmap(iconPath);
    } else if (iconPath.startsWith("data:image/")){
        // iconPath is a string representing an inline image.
        QStringList strs = iconPath.split("base64,");
        if (strs.length() == 2) {
            QByteArray data = QByteArray::fromBase64(strs.at(1).toLatin1());
            pixmap.loadFromData(data);
        }
    }else {
        // try to read the iconPath as a icon name.
        QString path = getThemeIconPath(iconPath, width);
        if (path.length() == 0){
            path = ":/skin/images/application-default-icon.svg";
        }
        if (path.endsWith(".svg")) {
            QSvgRenderer renderer(path);
            pixmap.fill(Qt::transparent);
            QPainter painter;
            painter.begin(&pixmap);
            renderer.render(&painter);
            painter.end();
            qDebug() << "path svg:" << path;
        } else {
            pixmap.load(path);
        }
    }

    return pixmap;
}