root/trunk/qt4-gui/src/views/floatyview.cpp

Revision 6463, 3.1 kB (checked in by flynd, 4 months ago)

Use a const pointer for user objects that are only fetched for read access. Fixed some places where we changed the user even though we just had a read lock.

Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 1999-2006 Licq developers
5 *
6 * Licq is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Licq is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Licq; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#include "floatyview.h"
22
23#include <QHeaderView>
24#include <QMouseEvent>
25
26#include <licq_user.h>
27
28#include "config/contactlist.h"
29#include "contactlist/contactlist.h"
30#include "contactlist/singlecontactproxy.h"
31#include "core/usermenu.h"
32#include "helpers/support.h"
33
34#include "contactdelegate.h"
35
36using namespace LicqQtGui;
37/* TRANSLATOR LicqQtGui::FloatyView */
38
39UserFloatyList FloatyView::floaties;
40
41FloatyView::FloatyView(ContactListModel* contactList, const ICQUser* licqUser,  QWidget* parent)
42  : UserViewBase(contactList, parent),
43  myPpid(licqUser->PPID())
44{
45  setWindowFlags(Qt::FramelessWindowHint);
46  Support::ghostWindow(winId());
47  setAttribute(Qt::WA_DeleteOnClose, true);
48
49  QString name;
50  name.sprintf("Floaty%d", floaties.size() + 1);
51  Support::setWidgetProps(this, name);
52
53  setWindowTitle(tr("%1 Floaty (%2)")
54      .arg(QString::fromUtf8(licqUser->GetAlias()))
55      .arg(licqUser->IdString()));
56
57  setFrameStyle(QFrame::Raised | QFrame::Box);
58  setSelectionMode(NoSelection);
59  header()->hide();
60
61  if (licqUser->IdString())
62  {
63    char* realId = 0;
64    ICQUser::MakeRealId(licqUser->IdString(), myPpid, realId);
65    myId = realId;
66    delete [] realId;
67  }
68
69  // Use a proxy model to get a single user from the contact list
70  myListProxy = new SingleContactProxy(myContactList, myId, myPpid, this);
71  setModel(myListProxy);
72
73  connect(Config::ContactList::instance(), SIGNAL(listLookChanged()), SLOT(configUpdated()));
74  configUpdated();
75
76  floaties.append(this);
77}
78
79FloatyView::~FloatyView()
80{
81  int pos = floaties.indexOf(this);
82  if (pos != -1)
83    floaties.remove(pos);
84}
85
86FloatyView* FloatyView::findFloaty(QString id, unsigned long ppid)
87{
88  for (int i = 0; i < floaties.size(); i++)
89  {
90    FloatyView* p = floaties.at(i);
91    if (p->myId == id && p->myPpid == ppid)
92      return p;
93  }
94
95  return NULL;
96}
97
98void FloatyView::mouseMoveEvent(QMouseEvent* event)
99{
100  UserViewBase::mouseMoveEvent(event);
101
102  // Move the floaty the same distance as the mouse has moved since button was pressed
103  if (event->buttons() & Qt::LeftButton)
104    move(event->globalPos() - myMousePressPos);
105}
106
107void FloatyView::configUpdated()
108{
109  // Set column widths
110  for (unsigned short i = 0; i < Config::ContactList::instance()->columnCount(); i++)
111    setColumnWidth(i, Config::ContactList::instance()->columnWidth(i));
112}
Note: See TracBrowser for help on using the browser.