KDE 2.0 Development
Total Page:16
File Type:pdf, Size:1020Kb
00 8911 FM 10/16/00 2:09 PM Page i KDE 2.0 Development David Sweet, et al. 201 West 103rd St., Indianapolis, Indiana, 46290 USA 00 8911 FM 10/16/00 2:09 PM Page ii KDE 2.0 Development ASSOCIATE PUBLISHER Michael Stephens Copyright © 2001 by Sams Publishing This material may be distributed only subject to the terms and conditions set ACQUISITIONS EDITOR forth in the Open Publication License, v1.0 or later (the latest version is Shelley Johnston presently available at http://www.opencontent.org/openpub/). DEVELOPMENT EDITOR Distribution of the work or derivative of the work in any standard (paper) book Heather Goodell form is prohibited unless prior permission is obtained from the copyright holder. MANAGING EDITOR No patent liability is assumed with respect to the use of the information con- Matt Purcell tained herein. Although every precaution has been taken in the preparation of PROJECT EDITOR this book, the publisher and author assume no responsibility for errors or omis- Christina Smith sions. Neither is any liability assumed for damages resulting from the use of the information contained herein. COPY EDITOR International Standard Book Number: 0-672-31891-1 Barbara Hacha Kim Cofer Library of Congress Catalog Card Number: 99-067972 Printed in the United States of America INDEXER Erika Millen First Printing: October 2000 PROOFREADER 03 02 01 00 4 3 2 1 Candice Hightower Trademarks TECHNICAL EDITOR Kurt Granroth All terms mentioned in this book that are known to be trademarks or service Matthias Ettrich marks have been appropriately capitalized. Sams Publishing cannot attest to Kurt Wall the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. TEAM COORDINATOR Pamalee Nelson Warning and Disclaimer MEDIA DEVELOPER Every effort has been made to make this book as complete and as accurate as Dan Scherf possible, but no warranty or fitness is implied. The information provided is on INTERIOR DESIGNER an “as is” basis. The authors and the publisher shall have neither liability nor Anne Jones responsibility to any person or entity with respect to any loss or damages aris- ing from the information contained in this book. COVER DESIGNER Aren Howell PRODUCTION Steve Geiselman 00 8911 FM 10/16/00 2:09 PM Page iii Overview Introduction PART I Fundamentals of KDE Application Programming 1 The K Desktop Environment Background 2 A Simple KDE Application 3 The Qt Toolkit 4 Creating Custom KDE Widgets 5 KDE User Interface Compliance 6 KDE Style Reference PART II Advanced KDE Widgets and UI Design Techniques 7 Further KDE Compliance 8 Using Dialog Boxes 9 Constructing a Responsive User Interface 10 Complex-Function KDE Widgets 11 Alternative Application Types PART III Application Interaction and Integration 12 Creating and Using Components (KParts) 13 DCOP—Desktop Communication Protocol 14 Multimedia PART IV Developer Tools and Support 15 Creating Documentation 16 Packaging and Distributing Code 17 Managing Source Code with CVS 18 The KDevelop IDE: The Integrated Development Environment for KDE 19 Licensing Issues 00 8911 FM 10/16/00 2:09 PM Page iv PART V: Appendixes A KDE-Related Licenses B KDE Class Reference C Answers Index 00 8911 FM 10/16/00 2:09 PM Page v Contents Introduction 1 PART I Fundamentals of KDE Application Programming 3 1 The K Desktop Environment Background 5 Motivation for a Free Desktop ................................................................6 Why Develop with KDE? ......................................................................7 KDE Organization and Resources ..........................................................9 System Requirements ............................................................................9 Obtaining and Installing KDE ................................................................9 Installing Binary Packages ..............................................................10 Installing Source Packages ..............................................................11 Licenses and Legalities ........................................................................11 Let’s Code, Already! ............................................................................12 2 A Simple KDE Application 13 The Linux/UNIX Programmer’s Desktop ............................................14 Necessities for Editing Code ..........................................................14 Debuggers Available for Linux ......................................................15 Compiling a KDE Program ..................................................................15 Using make ......................................................................................17 KDE Application Structure ..................................................................19 KApplication ..................................................................................19 KTMainWindow ..................................................................................20 A Typical main() Function ..............................................................22 GUI Elements ......................................................................................23 The Menubar ..................................................................................25 The Toolbar ....................................................................................28 The Status Line ................................................................................28 Programming Conventions ..................................................................28 Naming Conventions ......................................................................29 Class Documentation ......................................................................29 Summary ..............................................................................................29 Exercises ..............................................................................................30 3 The Qt Toolkit 31 What It Is For (Look and Feel) ............................................................32 Inside the Qt Toolkit ............................................................................32 QObject ............................................................................................33 QWidget ............................................................................................33 QPainter ..........................................................................................36 QPushButton ....................................................................................38 00 8911 FM 10/16/00 2:09 PM Page vi vi KDE 2.0 DEVELOPMENT Signals and Slots ..................................................................................40 Creating a Slot ................................................................................41 Emitting a Signal ............................................................................42 Connecting a Slot to a Signal ..........................................................42 Signals and Slots with Parameters ..................................................44 Slots in Temporary Classes ............................................................45 Meta Object Compiler (moc) ................................................................45 Using the moc Tool ..........................................................................46 Sample Use of the moc ....................................................................46 The Utility Classes ..............................................................................48 Templates ........................................................................................48 Standard Template Library (STL) ..................................................49 QList—A Qt Template Class ..........................................................49 Special Features (ImageIO, OpenGL, Mesa) ......................................51 ImageIO ..........................................................................................51 OpenGL, Mesa ................................................................................53 Summary ..............................................................................................56 Exercises ..............................................................................................56 4 Creating Custom KDE Widgets 57 Widget Basics ......................................................................................58 Understanding the QWidget Base Class ........................................58 Widget Attributes ............................................................................61 Signals and Slots ............................................................................61 Sample Widget Class Declaration ..................................................62 Documentation ................................................................................63 Painting Widgets ..................................................................................63 When Painting Occurs ....................................................................64 Repainting Efficiently ....................................................................64 Painting Your Widget with QPainter ..............................................65 Recording Drawing Commands with QPicture ..............................65 A Simple Widget ............................................................................65 Using Child Widgets ............................................................................71