summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabel/kbcataloglistview.cpp
blob: 40822862b62c4b339d1c7b88aeb8fd944a6903d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 2004 by Asgeir Frimannsson
                            <asgeirf@redhat.com>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

**************************************************************************** */

#include "kbcataloglistview.h"
#include "kbcataloglistviewitem.h"
#include "kbcatalog.h"
#include "kbabel.h"
#include "editcmd.h"

#include <tdelocale.h>
#include <tdelistview.h>
#include <tqcolor.h>
#include <tqlayout.h>
#include <tdeglobalsettings.h>

using namespace KBabel;

KBCatalogListView::KBCatalogListView(KBCatalog* catalog, TQWidget *parent, KBabel::Project::Ptr project)
 : TQWidget(parent)
{
    m_catalog= catalog;
    TQVBoxLayout* layout=new TQVBoxLayout(this);
    
    m_listview = new TDEListView(this, "catalogListView");
    m_listview->addColumn(i18n("Id"));
    m_listview->addColumn(i18n("Original String"));
    m_listview->addColumn(i18n("Translated String"));
    m_listview->setAlternateBackground(TDEGlobalSettings::alternateBackgroundColor());
    m_listview->setFullWidth(true);
    m_listview->setAllColumnsShowFocus(true);
    m_listview->resize(this->size());

    layout->addWidget(m_listview);
    layout->setStretchFactor(m_listview,1);
    
    connect(m_listview,TQT_SIGNAL(selectionChanged(TQListViewItem *)), this,TQT_SLOT(selectionChanged(TQListViewItem *)));
}

KBCatalogListView::~KBCatalogListView()
{
}


void KBCatalogListView::selectionChanged ( TQListViewItem * item)
{
    DocPosition pos;
    int number = m_items->find(reinterpret_cast<KBCatalogListViewItem*>(item));
    if(number<0) number = 0;
    
    pos.item=number;
    pos.form=0;
    
    emit signalSelectionChanged(pos);
}

void KBCatalogListView::setSelectedItem(int index)
{
    TQListViewItem * item = m_items->at(index);

    // block signals - don't reemit the selected item signal
    blockSignals(true);
    m_listview->setSelected(item, true);
    blockSignals(false);
    
    m_listview->ensureItemVisible(item);    
}

void KBCatalogListView::update(EditCommand* cmd, bool undo)
{
    /*
   if((int)_currentIndex==cmd->index())
   {
      emitEntryState();

      if(cmd->part()==Msgstr)
      {
         msgstrEdit->processCommand(cmd,undo);
	 emit signalMsgstrChanged();
      }
   }
   */
}

void KBCatalogListView::msgstrChanged(const TQString& str)
{
    KBCatalogListViewItem * item = reinterpret_cast<KBCatalogListViewItem *>(m_listview->selectedItem());
    item->setMsgStr(str);
}

void KBCatalogListView::slotNewFileOpened()
{
    m_listview->clear();
    KBCatalogListViewItem * tempItem;
    if(m_catalog)
    {
        m_items = new TQPtrVector<KBCatalogListViewItem>(m_catalog->numberOfEntries());
        
        for(uint i=0;i<m_catalog->numberOfEntries();i++)
        {
            TQString msgid = ( *m_catalog->msgid(i).at(0) );
            TQString msgstr = ( *m_catalog->msgstr(i).at(0) );
            tempItem = new KBCatalogListViewItem(m_listview,0,i+1,
                                            msgid,
                                            msgstr);
           m_items->insert(i, tempItem);   
        }
    }
    
    int width = m_listview->columnWidth(1) + m_listview->columnWidth(2);
    m_listview->setColumnWidth(1,width/2);
    m_listview->setColumnWidth(2,width/2);


}


#include "kbcataloglistview.moc"