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 #include <ArmarXGui/applications/ArmarXGui/ui_UseCaseSelectorItem.h>
26 #include <filesystem>
28 #include <QFile>
31 
32 namespace armarx
33 {
34 
35  UseCaseSelectorItem::UseCaseSelectorItem(const QString& title, const QString& description, const QString& configFilePath, const QString& packageName, QString iconPath, QWidget* parent) :
36  QWidget(parent),
37  ui(new Ui::UseCaseSelectorItem),
38  configFilePath(configFilePath)
39  {
40  ui->setupUi(this);
41  this->setToolTip(configFilePath);
42  ui->titleLabel->setText(title);
43  ui->descriptionLabel->setText(description);
44  std::filesystem::path p(configFilePath.toStdString());
45  p.filename().stem();
46  ui->filenameLabel->setText(QString(p.filename().string().c_str()) + " in " + packageName + " ");
47  QString finalPath = iconPath;
48  if (!iconPath.isEmpty())
49  {
50  if (!QFile::exists(iconPath))
51  {
52  auto copy = iconPath;
53  finalPath = PluginCache::GetIconCachePath() + "resources/" + copy.remove(0, 1);
54  }
55  if (!QFile::exists(finalPath))
56  {
57  finalPath = PluginCache::GetIconCachePath() + iconPath;
58  }
59  if (!QFile::exists(finalPath))
60  {
61  CMakePackageFinder f(packageName.toStdString());
62  if (f.packageFound())
63  {
64  std::filesystem::path path = f.getDataDir();
65  finalPath = QString::fromStdString((path / iconPath.toStdString()).string());
66  }
67  }
68  if (QFile::exists(finalPath))
69  {
70  QPixmap pixmap(finalPath);
71  if (!pixmap.isNull())
72  {
73  ui->iconLabel->setPixmap(pixmap.scaled(pixmapSize, pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
74  }
75  else
76  {
77  ARMARX_INFO_S << "Cannot find image: " << iconPath.toStdString();
78  }
79  }
80  }
81  }
82 
84  {
85  delete ui;
86  }
87 
89  {
90  return configFilePath;
91  }
92 
94  {
95  return highlighted;
96  }
97 
98  void UseCaseSelectorItem::highlight(bool highlight)
99  {
101  QPalette p(palette());
102  setAutoFillBackground(true);
103  if (highlight)
104  {
105  p.setColor(QPalette::Window, p.highlight().color());
106  }
107  else
108  {
109  p = qobject_cast<QWidget*>(parent())->palette();
110  }
111  setPalette(p);
112  }
113 
115  {
116  emit doubleClicked();
117  }
118 
119  void UseCaseSelectorItem::mouseReleaseEvent(QMouseEvent* event)
120  {
121  emit selected(configFilePath);
122  }
123 
124 }
armarx::UseCaseSelectorItem::UseCaseSelectorItem
UseCaseSelectorItem(const QString &title, const QString &description, const QString &configFilePath, const QString &packageName, QString iconPath, QWidget *parent=0)
Definition: UseCaseSelectorItem.cpp:35
armarx::UseCaseSelectorItem::isHighlighted
bool isHighlighted() const
Definition: UseCaseSelectorItem.cpp:93
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
UseCaseSelectorItem.h
armarx::UseCaseSelectorItem::getConfigFilePath
QString getConfigFilePath() const
Definition: UseCaseSelectorItem.cpp:88
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
armarx::UseCaseSelectorItem::~UseCaseSelectorItem
~UseCaseSelectorItem() override
Definition: UseCaseSelectorItem.cpp:83
armarx::UseCaseSelectorItem::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *) override
Definition: UseCaseSelectorItem.cpp:119
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:57
armarx::UseCaseSelectorItem::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *) override
Definition: UseCaseSelectorItem.cpp:114
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
armarx::UseCaseSelectorItem::doubleClicked
void doubleClicked()
armarx::UseCaseSelectorItem::highlight
void highlight(bool highlight)
Definition: UseCaseSelectorItem.cpp:98
CMakePackageFinder.h
armarx::PluginCache::GetIconCachePath
static QString GetIconCachePath()
Definition: PluginCache.cpp:179
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h
PluginCache.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::UseCaseSelectorItem::pixmapSize
const int pixmapSize
Definition: UseCaseSelectorItem.h:44