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 
36 namespace 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 
93  {
94  delete ui;
95  }
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
armarx::UseCaseSelectorItem::UseCaseSelectorItem
UseCaseSelectorItem(const QString &title, const QString &description, const QString &configFilePath, const QString &packageName, QString iconPath, QWidget *parent=0)
Definition: UseCaseSelectorItem.cpp:39
armarx::UseCaseSelectorItem::isHighlighted
bool isHighlighted() const
Definition: UseCaseSelectorItem.cpp:104
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:511
UseCaseSelectorItem.h
armarx::UseCaseSelectorItem::getConfigFilePath
QString getConfigFilePath() const
Definition: UseCaseSelectorItem.cpp:98
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:52
armarx::UseCaseSelectorItem::~UseCaseSelectorItem
~UseCaseSelectorItem() override
Definition: UseCaseSelectorItem.cpp:92
armarx::UseCaseSelectorItem::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *) override
Definition: UseCaseSelectorItem.cpp:133
armarx::UseCaseSelectorItem
Definition: UseCaseSelectorItem.h:35
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
copy
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: license.txt:39
armarx::UseCaseSelectorItem::selected
void selected(QString filepath)
armarx::UseCaseSelectorItem::highlighted
bool highlighted
Definition: UseCaseSelectorItem.h:63
armarx::UseCaseSelectorItem::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *) override
Definition: UseCaseSelectorItem.cpp:127
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:194
armarx::UseCaseSelectorItem::doubleClicked
void doubleClicked()
armarx::UseCaseSelectorItem::highlight
void highlight(bool highlight)
Definition: UseCaseSelectorItem.cpp:110
CMakePackageFinder.h
armarx::PluginCache::GetIconCachePath
static QString GetIconCachePath()
Definition: PluginCache.cpp:189
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:202
Logging.h
PluginCache.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::UseCaseSelectorItem::pixmapSize
const int pixmapSize
Definition: UseCaseSelectorItem.h:49