UseCaseSelectorItem.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "UseCaseSelectorItem.h"
25
26#include <filesystem>
27
28#include <QFile>
29
32
33#include <ArmarXGui/applications/ArmarXGui/ui_UseCaseSelectorItem.h>
35
36namespace armarx
37{
38
40 const QString& description,
41 const QString& configFilePath,
42 const QString& packageName,
43 QString iconPath,
44 QWidget* parent) :
45 QWidget(parent), ui(new Ui::UseCaseSelectorItem), configFilePath(configFilePath)
46 {
47 ui->setupUi(this);
48 this->setToolTip(configFilePath);
49 ui->titleLabel->setText(title);
50 ui->descriptionLabel->setText(description);
51 std::filesystem::path p(configFilePath.toStdString());
52 p.filename().stem();
53 ui->filenameLabel->setText(QString(p.filename().string().c_str()) + " in " + packageName +
54 " ");
55 QString finalPath = iconPath;
56 if (!iconPath.isEmpty())
57 {
58 if (!QFile::exists(iconPath))
59 {
60 auto copy = iconPath;
61 finalPath = PluginCache::GetIconCachePath() + "resources/" + copy.remove(0, 1);
62 }
63 if (!QFile::exists(finalPath))
64 {
65 finalPath = PluginCache::GetIconCachePath() + iconPath;
66 }
67 if (!QFile::exists(finalPath))
68 {
69 CMakePackageFinder f(packageName.toStdString());
70 if (f.packageFound())
71 {
72 std::filesystem::path path = f.getDataDir();
73 finalPath = QString::fromStdString((path / iconPath.toStdString()).string());
74 }
75 }
76 if (QFile::exists(finalPath))
77 {
78 QPixmap pixmap(finalPath);
79 if (!pixmap.isNull())
80 {
81 ui->iconLabel->setPixmap(pixmap.scaled(
82 pixmapSize, pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
83 }
84 else
85 {
86 ARMARX_INFO_S << "Cannot find image: " << iconPath.toStdString();
87 }
88 }
89 }
90 }
91
96
97 QString
99 {
100 return configFilePath;
101 }
102
103 bool
105 {
106 return highlighted;
107 }
108
109 void
111 {
113 QPalette p(palette());
114 setAutoFillBackground(true);
115 if (highlight)
116 {
117 p.setColor(QPalette::Window, p.highlight().color());
118 }
119 else
120 {
121 p = qobject_cast<QWidget*>(parent())->palette();
122 }
123 setPalette(p);
124 }
125
126 void
128 {
129 emit doubleClicked();
130 }
131
132 void
134 {
135 emit selected(configFilePath);
136 }
137
138} // namespace armarx
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
bool packageFound() const
Returns whether or not this package was found with cmake.
static QString GetIconCachePath()
UseCaseSelectorItem(const QString &title, const QString &description, const QString &configFilePath, const QString &packageName, QString iconPath, QWidget *parent=0)
void mouseDoubleClickEvent(QMouseEvent *) override
void selected(QString filepath)
void mouseReleaseEvent(QMouseEvent *) override
#define ARMARX_INFO_S
Definition Logging.h:202
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.