~ubuntu-branches/ubuntu/precise/kbibtex/precise

« back to all changes in this revision

Viewing changes to src/entrywidgettitle.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Hanke
  • Date: 2011-07-18 09:29:48 UTC
  • mfrom: (1.1.6) (2.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20110718092948-ksxjmg7kdfamolmg
Tags: 0.3-1
* First upstream release for KDE4 (Closes: #634255). A number of search
  engines are still missing, in comparison to the 0.2 series.
* Bumped Standards-Version to 3.9.2, no changes necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
*   Copyright (C) 2004-2009 by Thomas Fischer                             *
3
 
*   fischer@unix-ag.uni-kl.de                                             *
4
 
*                                                                         *
5
 
*   This program is free software; you can redistribute it and/or modify  *
6
 
*   it under the terms of the GNU General Public License as published by  *
7
 
*   the Free Software Foundation; either version 2 of the License, or     *
8
 
*   (at your option) any later version.                                   *
9
 
*                                                                         *
10
 
*   This program is distributed in the hope that it will be useful,       *
11
 
*   but 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, write to the                         *
17
 
*   Free Software Foundation, Inc.,                                       *
18
 
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
***************************************************************************/
20
 
#include <qlayout.h>
21
 
#include <qlabel.h>
22
 
#include <kdialog.h>
23
 
#include <klocale.h>
24
 
 
25
 
#include <fieldlineedit.h>
26
 
#include <value.h>
27
 
#include <entryfield.h>
28
 
#include "entrywidgettitle.h"
29
 
 
30
 
namespace KBibTeX
31
 
{
32
 
 
33
 
    EntryWidgetTitle::EntryWidgetTitle( BibTeX::File *bibtexfile, bool isReadOnly, QWidget *parent, const char *name )
34
 
            : EntryWidgetTab( bibtexfile, isReadOnly, parent, name )
35
 
    {
36
 
        setupGUI();
37
 
    }
38
 
 
39
 
    EntryWidgetTitle::~EntryWidgetTitle()
40
 
    {
41
 
        // nothing
42
 
    }
43
 
 
44
 
    bool EntryWidgetTitle::isModified()
45
 
    {
46
 
        return m_fieldLineEditTitle->isModified() || m_fieldLineEditBookTitle->isModified() || m_fieldLineEditSeries->isModified();
47
 
    }
48
 
 
49
 
    void EntryWidgetTitle::updateGUI( BibTeX::Entry::EntryType entryType, bool enableAll )
50
 
    {
51
 
        bool enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftTitle ) != BibTeX::Entry::frsIgnored;
52
 
        m_fieldLineEditTitle->setEnabled( enableWidget );
53
 
        m_fieldLineEditTitle->setFieldType( BibTeX::EntryField::ftTitle );
54
 
 
55
 
        enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftBookTitle ) != BibTeX::Entry::frsIgnored;
56
 
        m_fieldLineEditBookTitle->setEnabled( enableWidget );
57
 
        m_fieldLineEditBookTitle->setFieldType( BibTeX::EntryField::ftBookTitle );
58
 
 
59
 
        enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftSeries ) != BibTeX::Entry::frsIgnored;
60
 
        m_fieldLineEditSeries->setEnabled( enableWidget );
61
 
        m_fieldLineEditSeries->setFieldType( BibTeX::EntryField::ftSeries );
62
 
    }
63
 
 
64
 
    void EntryWidgetTitle::apply(BibTeX::Entry *entry  )
65
 
    {
66
 
        BibTeX::Value * value = m_fieldLineEditTitle->value();
67
 
        setValue( entry, BibTeX::EntryField::ftTitle, value );
68
 
        delete value;
69
 
 
70
 
        value = m_fieldLineEditBookTitle->value();
71
 
        setValue( entry, BibTeX::EntryField::ftBookTitle, value );
72
 
        delete value;
73
 
 
74
 
        value = m_fieldLineEditSeries->value();
75
 
        setValue( entry, BibTeX::EntryField::ftSeries, value );
76
 
        delete value;
77
 
    }
78
 
 
79
 
    void EntryWidgetTitle::reset(BibTeX::Entry *entry  )
80
 
    {
81
 
        BibTeX::EntryField * field = entry->getField( BibTeX::EntryField::ftTitle );
82
 
        m_fieldLineEditTitle->setValue( field != NULL ? field->value() : NULL );
83
 
 
84
 
        field = entry->getField( BibTeX::EntryField::ftBookTitle );
85
 
        m_fieldLineEditBookTitle->setValue( field != NULL ? field->value() : NULL );
86
 
 
87
 
        field = entry->getField( BibTeX::EntryField::ftSeries );
88
 
        m_fieldLineEditSeries->setValue( field != NULL ? field->value() : NULL );
89
 
    }
90
 
 
91
 
    void EntryWidgetTitle::updateWarnings( BibTeX::Entry::EntryType entryType, QListView *listViewWarnings )
92
 
    {
93
 
        bool crossRefValid = FALSE;
94
 
 
95
 
        addMissingWarning( entryType, BibTeX::EntryField::ftTitle, m_fieldLineEditTitle->caption(), !m_fieldLineEditTitle->isEmpty(), m_fieldLineEditTitle, listViewWarnings );
96
 
 
97
 
        crossRefValid = m_crossRefEntry != NULL &&  m_crossRefEntry->getField( BibTeX::EntryField::ftTitle ) != NULL;
98
 
        addMissingWarning( entryType, BibTeX::EntryField::ftBookTitle, m_fieldLineEditBookTitle->caption(), !m_fieldLineEditBookTitle->isEmpty() || crossRefValid, m_fieldLineEditBookTitle, listViewWarnings );
99
 
        if ( crossRefValid && m_fieldLineEditBookTitle->isEmpty() )
100
 
            addCrossRefInfo( m_fieldLineEditBookTitle->caption(), m_fieldLineEditBookTitle, listViewWarnings );
101
 
 
102
 
        addMissingWarning( entryType, BibTeX::EntryField::ftSeries, m_fieldLineEditSeries->caption(), !m_fieldLineEditSeries->isEmpty(), m_fieldLineEditSeries, listViewWarnings );
103
 
 
104
 
        addFieldLineEditWarning( m_fieldLineEditTitle, m_fieldLineEditTitle->caption(), listViewWarnings );
105
 
 
106
 
        addFieldLineEditWarning( m_fieldLineEditBookTitle, m_fieldLineEditBookTitle->caption(), listViewWarnings );
107
 
 
108
 
        addFieldLineEditWarning( m_fieldLineEditSeries, m_fieldLineEditSeries->caption(), listViewWarnings );
109
 
    }
110
 
 
111
 
    void EntryWidgetTitle::setupGUI()
112
 
    {
113
 
        QGridLayout * gridLayout = new QGridLayout( this, 4, 2, KDialog::marginHint(), KDialog::spacingHint(), "gridLayout" );
114
 
        gridLayout->setRowStretch( 3, 1 );
115
 
 
116
 
        QLabel *label = new QLabel( QString( "%1:" ).arg( i18n( "Title" ) ), this );
117
 
        gridLayout->addWidget( label, 0, 0 );
118
 
        m_fieldLineEditTitle = new KBibTeX::FieldLineEdit( i18n( "Title" ), KBibTeX::FieldLineEdit::itSingleLine, m_isReadOnly, this, "m_fieldLineEditTitle" );
119
 
        label->setBuddy( m_fieldLineEditTitle );
120
 
        gridLayout->addWidget( m_fieldLineEditTitle, 0, 1 );
121
 
 
122
 
        label = new QLabel( QString( "%1:" ).arg( i18n( "Book Title" ) ), this );
123
 
        gridLayout->addWidget( label, 1, 0 );
124
 
        m_fieldLineEditBookTitle = new KBibTeX::FieldLineEdit( i18n( "Book Title" ), KBibTeX::FieldLineEdit::itSingleLine, m_isReadOnly, this, "m_fieldLineEditBookTitle" );
125
 
        label->setBuddy( m_fieldLineEditBookTitle );
126
 
        gridLayout->addWidget( m_fieldLineEditBookTitle, 1, 1 );
127
 
 
128
 
        label = new QLabel( QString( "%1:" ).arg( i18n( "Series" ) ), this );
129
 
        gridLayout->addWidget( label, 2, 0 );
130
 
        m_fieldLineEditSeries = new KBibTeX::FieldLineEdit( i18n( "Series" ), KBibTeX::FieldLineEdit::itSingleLine, m_isReadOnly, this, "m_fieldLineEditSeries" );
131
 
        label->setBuddy( m_fieldLineEditSeries );
132
 
        gridLayout->addWidget( m_fieldLineEditSeries, 2, 1 );
133
 
    }
134
 
 
135
 
}
136
 
#include "entrywidgettitle.moc"