Commit 8a5ea283 authored by Geoff's avatar Geoff
Browse files

Import: Add of the first working version of the tagging system

parent dc1cb387
......@@ -28,10 +28,10 @@
#include <math.h>
TagWidget::TagWidget( QWidget *parent, int nbButton, QStringList tagList ) :
QWidget( parent ), m_ui( new Ui::TagWidget ), m_nbButton( nbButton ), m_defaultTagList( tagList )
QWidget( parent ), m_ui( new Ui::TagWidget ), m_nbButton( nbButton ), m_defaultTagList( tagList ), m_currentMedia( NULL )
{
m_ui->setupUi( this );
m_defaultTagList << "Ta chatte" << "Maman" << "Chiwawa" << "Bite" << "Porcinet";
m_defaultTagList << "Salade" << "Ognon" << "Tomate" << "Mayo" << "Ketchup";
int nbRow = sqrt( nbButton );
int x = 0;
......@@ -45,21 +45,20 @@ TagWidget::TagWidget( QWidget *parent, int nbButton, QStringList tagList ) :
y++;
}
QPushButton* button = new QPushButton();
button->setCheckable( true );
connect( button, SIGNAL( clicked() ), this, SLOT( buttonTagClicked() ) );
m_buttonList.append( button );
m_ui->buttonGridLayout->addWidget( button, x++, y );
}
for( int i = 0; i < m_defaultTagList.count(); i++ )
if ( i < m_buttonList.count() )
{
static_cast<QPushButton*>( m_buttonList[i])->setText( m_defaultTagList[i] );
static_cast<QPushButton*>( m_buttonList[i])->setEnabled( false );
}
setTagTextEdit();
m_completer = new QCompleter( m_defaultTagList, this );
m_completer->setCaseSensitivity( Qt::CaseInsensitive );
m_ui->KeywordTagLineEdit->setCompleter( m_completer );
connect( m_ui->AddButton, SIGNAL( clicked() ), this, SLOT( tagAdded() ) );
connect( m_ui->TagTextEdit, SIGNAL( textChanged() ), this, SLOT( setMetaTags() ) );
}
TagWidget::~TagWidget()
......@@ -67,25 +66,68 @@ TagWidget::~TagWidget()
delete m_ui;
}
void TagWidget::setTagTextEdit()
void TagWidget::mediaSelected( Media* media )
{
QString tags;
for( int i = 0; i < m_defaultTagList.count(); i++ )
tags += " " + m_defaultTagList[i];
m_ui->TagTextEdit->setText(tags);
m_currentMedia = media;
setTagTextEdit();
for (int i = 0; i < m_buttonList.count(); i++)
{
static_cast<QPushButton*>( m_buttonList[i])->setEnabled( true );
if ( m_currentMedia->getMetaTags().contains( static_cast<QPushButton*>(m_buttonList[i])->text() ) )
static_cast<QPushButton*>(m_buttonList[i])->setChecked( true );
else
static_cast<QPushButton*>(m_buttonList[i])->setChecked( false );
}
}
void TagWidget::tagAdded()
void TagWidget::setMetaTags()
{
m_defaultTagList << m_ui->KeywordTagLineEdit->text();
m_ui->KeywordTagLineEdit->clear();
setTagTextEdit();
if ( m_currentMedia != NULL )
{
QStringList tagList = m_ui->TagTextEdit->document()->toPlainText().split( ",", QString::SkipEmptyParts );
m_currentMedia->setMetaTags( tagList );
}
}
void TagWidget::mediaSelected( Media* media )
void TagWidget:: buttonTagClicked()
{
m_currentMedia = media;
setTagTextEdit();
if ( m_currentMedia != NULL )
{
QStringList tagList = m_currentMedia->getMetaTags();
for (int i = 0; i < m_buttonList.count(); i++)
{
QPushButton* button = static_cast<QPushButton*>(m_buttonList[i]);
if ( button->isChecked() && !tagList.contains( button->text() ) )
tagList << button->text();
else if ( !button->isChecked() && tagList.contains( button->text() ) )
tagList.removeAll( button->text() );
}
m_currentMedia->setMetaTags( tagList );
setTagTextEdit();
}
}
void TagWidget::setTagTextEdit()
{
QString tags;
if ( m_currentMedia != NULL )
{
for( int i = 0; i < m_currentMedia->getMetaTags().count(); i++ )
if (i == 0)
tags += m_currentMedia->getMetaTags()[i];
else
tags += "," + m_currentMedia->getMetaTags()[i];
m_ui->TagTextEdit->setText(tags);
setButtonList( m_defaultTagList );
}
}
void TagWidget::setButtonList( QStringList tagList )
{
if ( m_currentMedia != NULL )
for( int i = 0; i < tagList.count(); i++ )
if ( i < m_buttonList.count() )
static_cast<QPushButton*>( m_buttonList[i] )->setText( tagList[i] );
}
void TagWidget::changeEvent( QEvent *e )
......
......@@ -47,6 +47,8 @@ class TagWidget : public QWidget
protected:
void changeEvent( QEvent *e );
void setTagTextEdit();
void setButtonList( QStringList tagList );
bool isButtonExist();
private:
Ui::TagWidget* m_ui;
......@@ -54,11 +56,11 @@ class TagWidget : public QWidget
QStringList m_defaultTagList;
QWidgetList m_buttonList;
Media* m_currentMedia;
QCompleter* m_completer;
public slots:
void mediaSelected( Media* media );
void tagAdded();
void buttonTagClicked();
void setMetaTags();
};
#endif // TAGWIDGET_H
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>895</width>
<height>721</height>
<width>850</width>
<height>730</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -16,8 +16,20 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>850</width>
<height>730</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>850</width>
<height>730</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Import</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="4">
......@@ -138,7 +150,7 @@
<item row="2" column="1" rowspan="2">
<widget class="QWidget" name="TagWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>571</height>
<width>500</width>
<height>674</height>
</rect>
</property>
<property name="sizePolicy">
......
......@@ -18,8 +18,8 @@
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
<width>328</width>
<height>190</height>
</size>
</property>
<property name="windowTitle">
......@@ -33,26 +33,19 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="KeywordTagLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="AddButton">
<item row="1" column="0" colspan="2">
<widget class="QTextEdit" name="TagTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add</string>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
</widget>
</item>
......@@ -63,29 +56,19 @@
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QTextEdit" name="TagTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<item row="2" column="1">
<widget class="QComboBox" name="KeywordSetComboBox"/>
</item>
<item row="4" column="0" colspan="3">
<item row="3" column="0" colspan="2">
<layout class="QGridLayout" name="buttonGridLayout" rowstretch="0">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="spacing">
<number>-1</number>
<number>6</number>
</property>
</layout>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="KeywordSetComboBox"/>
</item>
</layout>
</widget>
<resources/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment