• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • editor
imagechooserwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "imagechooserwidget.h"
17 
18 #include <keduvocexpression.h>
19 #include <kdebug.h>
20 #include <KMimeType>
21 
22 #include <QDragEnterEvent>
23 
24 using namespace Editor;
25 
26 ImageChooserWidget::ImageChooserWidget(QWidget *parent) : QWidget(parent)
27 {
28  setupUi(this);
29  m_currentTranslation = -1;
30 
31  connect(imageUrlRequester, SIGNAL(textChanged(const QString&)), SLOT(slotImageChanged(const QString&)));
32 
33  imageWidget->setAcceptDrops(true);
34  imageWidget->installEventFilter(this);
35  setEnabled(false);
36 }
37 
38 void ImageChooserWidget::setTranslation(KEduVocExpression* entry, int translation)
39 {
40  m_currentTranslation = translation;
41  m_entry = entry;
42 
43  if (m_entry) {
44  setEnabled(true);
45  imageUrlRequester->setUrl(m_entry->translation(m_currentTranslation)->imageUrl().toLocalFile());
46 // slotImageChanged( m_entry->translation(m_currentTranslation)->imageUrl().toLocalFile() );
47  } else {
48  setEnabled(false);
49  imageUrlRequester->clear();
50 // imageLabel->setText(i18nc("@label image preview is empty", "No Preview"));
51  imageWidget->setPixmap(QPixmap());
52  }
53 }
54 
55 void ImageChooserWidget::slotImageChanged(const QString & url)
56 {
57  if (!url.isEmpty()) {
58  QPixmap pixmap(url);
59  imageWidget->setPixmap(pixmap);
60  } else {
61 // imageLabel->setText(i18nc("@label image preview is empty", "No Image"));
62  imageWidget->setPixmap(QPixmap());
63  }
64 
65  if (m_entry) {
66  m_entry->translation(m_currentTranslation)->setImageUrl(KUrl(url));
67  foreach(int j, m_entry->translationIndices()) {
68  if (m_entry->translation(j)->imageUrl().isEmpty()) {
69  m_entry->translation(j)->setImageUrl(imageUrlRequester->url());
70  }
71  }
72  }
73 }
74 
75 bool ImageChooserWidget::eventFilter(QObject * obj, QEvent * event)
76 {
77  if (obj == imageWidget) {
78 // if (event->type() == QEvent::KeyPress) {
79 // QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
80 // kDebug() << "Ate key press " << keyEvent->key();
81 // return true;
82 // }
83 // if (event->type() == QEvent::Resize) {
84 // QPixmap pixmap(imageUrlRequester->url().toLocalFile());
85 // imageLabel->setPixmap(pixmap.scaled(imageLabel->size(), Qt::KeepAspectRatio));
86 // return false;
87 // }
88 
89 
90  if (event->type() == QEvent::DragMove) {
91  event->accept();
92  return true;
93  }
94 
95  //Events with drop data
96  if (event->type() == QEvent::DragEnter || event->type() == QEvent::Drop) {
97  if (!m_entry) {
98  return true;
99  }
100  QDropEvent *dropEvent = dynamic_cast<QDropEvent *>(event);
101  if (( dropEvent!= NULL ) && dropEvent->provides("text/uri-list")) {
102  const QMimeData * mimeData( dropEvent->mimeData() );
103  if ( mimeData && mimeData->hasUrls() ) {
104  const QList<QUrl > qurls(mimeData->urls() ) ;
105  if ( !qurls.empty() ) {
106  const QUrl & qurl (qurls.first() );
107 
108  switch( event->type() ) {
109  case QEvent::DragEnter: {
110  const QString name(KMimeType::findByUrl(qurl)->name());
111  if (name.startsWith("image")) {
112  event->accept();
113  return true;
114  }
115  break;
116  }
117  case QEvent::Drop:
118  imageUrlRequester->setUrl(qurl);
119  return true;
120  break;
121  default:
122  break;
123  }
124 
125  }
126  }
127  }
128  }
129  }
130  return QObject::eventFilter(obj, event);
131 }
132 
133 #include "imagechooserwidget.moc"
QEvent
QWidget
QEvent::type
Type type() const
QWidget::dropEvent
virtual void dropEvent(QDropEvent *event)
QWidget::setupUi
void setupUi(QWidget *widget)
QDropEvent::mimeData
const QMimeData * mimeData() const
imagechooserwidget.h
Editor::ImageChooserWidget::setTranslation
void setTranslation(KEduVocExpression *entry, int translation)
Update the word.
Definition: imagechooserwidget.cpp:38
QDropEvent::provides
virtual bool provides(const char *mimeType) const
QMimeData
QObject::name
const char * name() const
QWidget::setEnabled
void setEnabled(bool)
Editor::ImageChooserWidget::ImageChooserWidget
ImageChooserWidget(QWidget *parent=0)
Definition: imagechooserwidget.cpp:26
QObject
QDropEvent
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QObject::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
QString
QList
QPixmap
Editor::ImageChooserWidget::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Definition: imagechooserwidget.cpp:75
QUrl
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QWidget::event
virtual bool event(QEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal