Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | List of all members
geometrize::dialog::TemplateButton::TemplateButtonImpl Class Reference
Collaboration diagram for geometrize::dialog::TemplateButton::TemplateButtonImpl:
Collaboration graph
[legend]

Public Member Functions

 TemplateButtonImpl (TemplateButton *pQ, chaiscript::ChaiScript *const templateLoader, const QString &templateFolder)
 
 ~TemplateButtonImpl ()
 
TemplateButtonImpl operator= (const TemplateButtonImpl &)=delete
 
 TemplateButtonImpl (const TemplateButtonImpl &)=delete
 
QImage setupTemplate ()
 
void openTemplate ()
 
void revealTemplateInExplorer ()
 
void showContextMenu (QContextMenuEvent *e)
 
TemplateManifest getTemplateManifest () const
 
void onLanguageChange ()
 

Private Member Functions

void populateUi ()
 
void setButtonToolTipText ()
 

Private Attributes

std::unique_ptr
< Ui::TemplateButton > 
ui
 
TemplateButtonq
 
chaiscript::ChaiScript *const m_templateLoader
 
const QString m_templateFolder
 
TemplateManifest m_manifest
 
QFutureWatcher< QImage > m_templateLoaderWatcher
 
QFuture< QImage > m_templateFuture
 

Constructor & Destructor Documentation

geometrize::dialog::TemplateButton::TemplateButtonImpl::TemplateButtonImpl ( TemplateButton pQ,
chaiscript::ChaiScript *const  templateLoader,
const QString &  templateFolder 
)
inline
29  :
30  ui(std::make_unique<Ui::TemplateButton>()),
31  q{pQ},
32  m_templateLoader{templateLoader},
33  m_templateFolder{templateFolder},
34  m_manifest{} // Loaded asynchronously later
35  {
36  ui->setupUi(q);
37  populateUi();
38 
39  q->connect(q, &TemplateButton::clicked, [this]() {
40  openTemplate();
41  });
42 
43  q->connect(&m_templateLoaderWatcher, &QFutureWatcher<QImage>::finished, [this]() {
44  const QImage thumbnail{m_templateLoaderWatcher.future().result()};
45 
46  ui->imageLabel->setPixmap(QPixmap::fromImage(thumbnail));
47 
49 
51  });
52 
53  m_templateFuture = QtConcurrent::run(this, &TemplateButtonImpl::setupTemplate);
55  }
QImage setupTemplate()
Definition: templatebutton.cpp:65
void signal_templateLoaded(QString, bool)
chaiscript::ChaiScript *const m_templateLoader
Definition: templatebutton.cpp:138
void setButtonToolTipText()
Definition: templatebutton.cpp:129
std::unique_ptr< Ui::TemplateButton > ui
Definition: templatebutton.cpp:136
const QString m_templateFolder
Definition: templatebutton.cpp:139
void openTemplate()
Definition: templatebutton.cpp:81
QFutureWatcher< QImage > m_templateLoaderWatcher
Definition: templatebutton.cpp:141
TemplateManifest m_manifest
Definition: templatebutton.cpp:140
TemplateButton * q
Definition: templatebutton.cpp:137
QFuture< QImage > m_templateFuture
Definition: templatebutton.cpp:142
void populateUi()
Definition: templatebutton.cpp:124
geometrize::dialog::TemplateButton::TemplateButtonImpl::~TemplateButtonImpl ( )
inline
58  {
59  m_templateFuture.waitForFinished(); // Wait for template to finish loading
60  }
QFuture< QImage > m_templateFuture
Definition: templatebutton.cpp:142
geometrize::dialog::TemplateButton::TemplateButtonImpl::TemplateButtonImpl ( const TemplateButtonImpl )
delete

Member Function Documentation

TemplateManifest geometrize::dialog::TemplateButton::TemplateButtonImpl::getTemplateManifest ( ) const
inline
113  {
114  return m_manifest;
115  }
TemplateManifest m_manifest
Definition: templatebutton.cpp:140
void geometrize::dialog::TemplateButton::TemplateButtonImpl::onLanguageChange ( )
inline
118  {
119  ui->retranslateUi(q);
120  populateUi();
121  }
std::unique_ptr< Ui::TemplateButton > ui
Definition: templatebutton.cpp:136
TemplateButton * q
Definition: templatebutton.cpp:137
void populateUi()
Definition: templatebutton.cpp:124

Here is the call graph for this function:

void geometrize::dialog::TemplateButton::TemplateButtonImpl::openTemplate ( )
inline
82  {
84  }
chaiscript::ChaiScript *const m_templateLoader
Definition: templatebutton.cpp:138
const QString m_templateFolder
Definition: templatebutton.cpp:139
bool openTemplate(chaiscript::ChaiScript &engine, const std::string &templateFolder)
Definition: taskutil.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

TemplateButtonImpl geometrize::dialog::TemplateButton::TemplateButtonImpl::operator= ( const TemplateButtonImpl )
delete
void geometrize::dialog::TemplateButton::TemplateButtonImpl::populateUi ( )
inlineprivate
125  {
127  }
void setButtonToolTipText()
Definition: templatebutton.cpp:129

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::dialog::TemplateButton::TemplateButtonImpl::revealTemplateInExplorer ( )
inline
87  {
89  }
bool openInDefaultApplication(const std::string &path)
openInDefaultApplication Opens the given path in the default application.
Definition: util.cpp:220
const QString m_templateFolder
Definition: templatebutton.cpp:139

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::dialog::TemplateButton::TemplateButtonImpl::setButtonToolTipText ( )
inlineprivate
130  {
131  const QString name{tr("Name: %1", "Text on a label containing the name of an item, usually an image e.g. Name: The Mona Lisa").arg(QString::fromStdString(m_manifest.getName()))};
132  const QString license{tr("License: %2", "Text on a label containing the legal license a piece of media is under, usually an image e.g. License: Public Domain").arg(QString::fromStdString(m_manifest.getLicense()))};
133  q->setToolTip(name + "<br>" + license);
134  }
std::string getLicense() const
Definition: templatemanifest.cpp:68
TemplateManifest m_manifest
Definition: templatebutton.cpp:140
TemplateButton * q
Definition: templatebutton.cpp:137
std::string getName() const
Definition: templatemanifest.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function:

QImage geometrize::dialog::TemplateButton::TemplateButtonImpl::setupTemplate ( )
inline
66  {
67  // Note assuming this is threadsafe
69 
70  // Note assuming this is threadsafe
71  const QString imageFilepath{QString::fromStdString(util::getFirstFileWithExtensions(m_templateFolder.toStdString(), format::getReadableImageFileExtensions(false)))};
72 
73  const QImage thumbnail(imageFilepath);
74  if(!thumbnail.isNull()) {
75  const QSize size{180, 180};
76  return thumbnail.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::FastTransformation);
77  }
78  return thumbnail;
79  }
const QString m_templateFolder
Definition: templatebutton.cpp:139
TemplateManifest getTemplateManifest(const std::string &templateFolder)
Definition: taskutil.cpp:93
std::string getFirstFileWithExtensions(const std::string &dirPath, const std::vector< std::string > &extensions)
getFirstFileWithExtensions Gets the absolute file path to the first file with one of the given extens...
Definition: util.cpp:181
std::vector< std::string > getReadableImageFileExtensions(const bool includeDotPrefix)
getReadableImageFileExtensions Gets the lower-case image file extensions that have read support...
Definition: formatsupport.cpp:11
TemplateManifest m_manifest
Definition: templatebutton.cpp:140

Here is the call graph for this function:

void geometrize::dialog::TemplateButton::TemplateButtonImpl::showContextMenu ( QContextMenuEvent *  e)
inline
92  {
93  QMenu itemContextMenu;
94 
95  QAction openAction(tr("Open", "Text on a menu item the user presses to open a file/image"));
96  itemContextMenu.addAction(&openAction);
97  connect(&openAction, &QAction::triggered, [this]() {
98  openTemplate();
99  });
100 
101  if(!m_templateFolder.startsWith(":")) { // Only if it's not an embedded resource
102  QAction openInDefaultViewer(tr("Reveal in file explorer", "Text on a menu item the user presses to open an image/piece of media in a file viewer/explorer"));
103  itemContextMenu.addAction(&openInDefaultViewer);
104  connect(&openInDefaultViewer, &QAction::triggered, [this]() {
106  });
107  }
108 
109  itemContextMenu.exec(e->globalPos());
110  }
const QString m_templateFolder
Definition: templatebutton.cpp:139
void openTemplate()
Definition: templatebutton.cpp:81
void revealTemplateInExplorer()
Definition: templatebutton.cpp:86

Here is the call graph for this function:

Member Data Documentation

TemplateManifest geometrize::dialog::TemplateButton::TemplateButtonImpl::m_manifest
private
const QString geometrize::dialog::TemplateButton::TemplateButtonImpl::m_templateFolder
private
QFuture<QImage> geometrize::dialog::TemplateButton::TemplateButtonImpl::m_templateFuture
private
chaiscript::ChaiScript* const geometrize::dialog::TemplateButton::TemplateButtonImpl::m_templateLoader
private
QFutureWatcher<QImage> geometrize::dialog::TemplateButton::TemplateButtonImpl::m_templateLoaderWatcher
private
TemplateButton* geometrize::dialog::TemplateButton::TemplateButtonImpl::q
private
std::unique_ptr<Ui::TemplateButton> geometrize::dialog::TemplateButton::TemplateButtonImpl::ui
private

The documentation for this class was generated from the following file: